Is it somehow possible to get the delta time outside of _process?
The only idea I had is to create a singleton or autoload where I get the delta time from. But I want to avoid this.
Is it somehow possible to get the delta time outside of _process?
The only idea I had is to create a singleton or autoload where I get the delta time from. But I want to avoid this.
Like, create a variable at the script scope then set it from the process function. Would that work for you?
var delta: float
func _process(_delta: float) → void:
delta = _delta
You can also use
Example:
extends Node2D
func step():
position.x += speed * get_process_delta_time()
You can also get delta globally with:
var delta: float = Engine.get_main_loop().root.get_process_delta_time()
Edit: Added how to get delta globally.
I thought about this too. But I wanted to have delta in a function in a class that extends RefCounted and have only the node as argument, so indicainkwells solutions is exactly what I was looking for. Thanks for the suggestion.
Thanks! I didn’t know this existed. Exactly what I was looking for!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.