Hello, I recently moved from gdscript to C# in an attempt to improv my programming skills (I'm a newbie, using Godot to learn, and I just got into C#). Now, something very simple in gdscript. In gdscript, to access the property playback in the AnimationTree, and set up a state_machine.travel("state"), you simply do:
var state_machine = $AnimationTree.get("parameters/playback")
state_machine.travel("some_state")
How do I do this is C#? I tried:
public class Player : Node2D {
public AnimationTree animTree;
public AnimationNodeStateMachinePlayback stateMachine;
public void _Ready() {
animTree = GetNode<AnimationTree>("path/to/my/Animation/Tree");
stateMachine = (AnimationNodeStateMachinePlayback)animTree.Get("/parameters/playback");
// also tried with "as"
stateMachine.Travel("state");
// this line ^ gives an error only in Godot, SEE BELOW.
}
}
The error that the Travel method gives me is:
E 0:00:00.520 void Player._Ready(): System.NullReferenceException:
Object reference not set to an instance of an object.
<C++ Error> Unhandled exception
<C++ Source> my/path/to/Player.cs:37 @ void Player._Ready()()
Player.cs:37 @ void Player._Ready()()
I can't call any method in stateMachine (like stateMachine.Start() / Stop() etc.), it always gives me this error.
I believe it is some C# "uniqueness", if one of you could elaborate to me, I'd be extremely happy! Thank you so much in advance!