Let's say i have following setup:

// State.cs
public class State: Node {}

// Walk.cs
public class Walk : State {}

// StateMachine.cs
public override void _Ready()
{
var node = new State();
node.Name = "WalkState";
AddChild(node);
node.SetScript(ResourceLoader.Load("res://Scenes/Actors/Player/Walk.cs"));
}

class methods ready, process, _physics_process isn't beign executed. why? but if i call class name itself, everything works.

var node = new Walk();
AddChild(node);

is here any way to instanciate class by name? lets say i have array with string names: {"walk", "stand", "jump"}

alrighty then, i managed to instanciate classes by class. For some reason following doesn't work for me. https://stackoverflow.com/questions/15449800/create-object-instance-of-a-class-having-its-name-in-string-variable

// State.cs
public class State: Node {}
// Walk.cs
public class Walk : State {}
// Run.cs
public class Run : State {}
// StateMachine.cs
private State[] states = new State[] {new Walk(), new Run() };  // define array of states

public override void _Ready()
{
	foreach (var state in states)
        {
            AddChild(state);
            state.Name = state.GetType().Name;  // optional
        }
}
2 years later