Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Timer nodes to ignore engine time scale #96626

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

hakro
Copy link
Contributor

@hakro hakro commented Sep 5, 2024

Sometimes, you don't want the Timer nodes to be impacted by the Engine.time_scale setting. This would be the case for example when you want to make HTTP calls to a server at regular intervals, without being affected by the time scale.

This PR adds the possibility to ignore Engine.time_scale in Timer nodes.

Screenshot_20240905_225805

Note that this feature is already present when using SceneTreeTimer create_timer(time_sec: float, process_always: bool = true, process_in_physics: bool = false, ignore_time_scale: bool = false)

But SceneTreeTimer is only one_shot, and thus cannot be an alternative solution when you need to run a function at regular intervals.

Testing this PR should be pretty straight forward.

1 - Add a Node2D, with a Label and Timer nodes as children
2 - Give the Timer something like 100 seconds wait time
3 - Add the script below
4 - Run the game, then check & uncheck the Ignore Time Scale from the editor to see the difference

extends Node2D

@onready var label : Label = $Label
@onready var timer : Timer = $Timer

func _physics_process(delta: float) -> void:
	
	Engine.time_scale = 10
	label.text = "Timeout left : " + str(timer.time_left)

@hakro hakro requested a review from a team as a code owner September 5, 2024 21:06
@hakro hakro force-pushed the steady_as_she_goes branch 2 times, most recently from 87b2fad to 9baae4c Compare September 5, 2024 21:39
@hakro hakro requested a review from a team as a code owner September 5, 2024 21:39
@hakro hakro force-pushed the steady_as_she_goes branch from 9baae4c to 1e6e24e Compare September 5, 2024 21:50
@Calinou Calinou added this to the 4.x milestone Sep 5, 2024
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is completely fine. Now it's worth questioning if this is the way to go.

@hakro
Copy link
Contributor Author

hakro commented Nov 11, 2024

Documentation is completely fine. Now it's worth questioning if this is the way to go.

To be clear, this PR is only to bring Timer on par with SceneTreeTimer, using pretty much the same code.

If a rework of both nodes is to be planned sometime soon, then indeed this PR might not be needed.

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Overall, this change makes sense to me.

I haven't tested it, but I did compare the implementation with SceneTreeTimer and they work the same.

scene/main/timer.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga requested a review from KoBeWi December 17, 2024 21:35
@hakro hakro force-pushed the steady_as_she_goes branch from 1e6e24e to 483c134 Compare December 19, 2024 17:41
@akien-mga akien-mga modified the milestones: 4.x, 4.4 Dec 20, 2024
@akien-mga akien-mga merged commit 7d5b23c into godotengine:master Dec 20, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants