I’ve been using Godot a lot recently, but I’ve run into a slight problem: I don’t know how to run code before the first frame of the scene renders.
So, for example, say in my scene I want my character to move to a different position at the start of the scene. If I change his position in the _ready() function, it happens after the scene has already rendered him in his initial position, and so you can clearly see him change position.
Is there any way to move him before the scene renders, so that it looks like he started in that new position? Thanks!
p.s. I really hope that this made sense. Thanks again!
There is one method named “_init()” that you may use to achieve what you want.
This is what the docs say:
● void _init() virtual
Called when the object’s script is instantiated, oftentimes after the object is initialized in memory (through Object.new() in GDScript, or new GodotObject in C#). It can be also defined to take in parameters. This method is similar to a constructor in most programming languages.
Note: If _init() is defined with required parameters, the Object with script may only be created directly. If any other means (such as PackedScene.instantiate() or Node.duplicate()) are used, the script’s initialization will fail.
I believe you could set the player’s position there, not sure though