How do a set a variable of a child node within the same scene?

Godot Version

4.3

Question

I’m currently trying to separate client input from the main player script for full server authoritative gameplay. Clients only send input and the server translates that input into game logic.

However, I still need to give the player authority over their input script/node. I tried doing this by calling the input node and passing the Player_ID variable

Player Script:

Client Input Script:

Player Scene Tree:
image

However, when I try it, ClientInput’s Player_ID is always null.

How can I send variables down the scene tree?

I think client input _enter _tree is called before player _ready

1 Like

_ready has no code inside it. (Hence, the pass keyword. So the order doesn’t matter at all and is unrelated to my question.

Your code is evaluated in this order, which is why you get a null value

Try creating a setter function on your client input script and react only when your player node pushes the data

1 Like

Whoops. My bad. I thought you were talking about the client input script alone. I’ll give it a shot.

I figured it out.

I can trigger a setter function from the player script:
image

Then, it applies to the client input script:

Result in the console:
image

@francois.delataste Thanks for your help, and sorry again for my misunderstanding.

Edit: You can also simplify the setter line from the player script by passing the variable.

Player Script:


image

Client Input Script:

1 Like

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