The Godot Community Forums are back up and running! Please read the the announcement post for important information on what happened. Thanks!

(Mono) How instanciate custom class as Node?

boruokboruok Posts: 18Member
edited September 10 in Programming

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"}

Best Answer

Answers

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file