Setting the script on a node after the node has been added to the tree prevents callbacks to _physics_process()

Godot Version

4.3 stable

Question

Is it expected behavior that declared methods _physics_process(), _input(), _process(), etc. are ignored if the script which contains them is attached to a node after _init() has been called?

For example, setting the script onto the node in _init() results in the expected behavior:

Figure 1
image

When I run the game, _physics_process() is called:

Figure 2
image

However, if I attach the script in _ready():

Figure 3
image
then the process callbacks are seemingly ignored. Is this because process callbacks are set when the node is added to the tree?

The context for this is that I’m messing around with dependency injection and am trying to get a reference to a Camera3D child of CharacterBody3D i.e.:

I am trying to inject the Camera3D reference from the ‘PlayerModel’ into the Player : WorldObject (see Figure1)

WorldObjects are psuedo-abstract data types which inherit RefCounted

Any help, clarification, and/or suggestions would be greatly appreciated! Thank you.

Okay so with the help of one of my buddies we actually figured out the solution. I couldn’t find it in the documentation anywhere, and at the very least it’s not in the obvious place i.e.:


but it turns out that when you set a script, it disables process calls.
It’s not enough to set_process_mode(), you have to actually call set_process(true), set_process_physics(true), etc.

i.e.:
image

It seems that you DON’T have to do this if you set the script prior to _ready(), for some reason… I thought that maybe process() was enabled on _init(), but that can’t be true because _init() is called when you set the script… very strange!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.