Skip to content

Source Generators

Valk edited this page Oct 18, 2024 · 3 revisions

Cat Lips Source Generators

For full explanations and a complete list of all of Cat Lips source generators, visit https://github.com/Cat-Lips/GodotSharp.SourceGenerators

OnInstantiate

Add the following to any node script.

[OnInstantiate]
private void Init() // optionally add params here
{

}

Then from anywhere do the following.

MyNode myNode = MyNode.Instantiate();
AddChild(myNode);

SceneTree

Add [SceneTree] attribute to the top of any class and you will be able to do some really cool things! Note that this only works for root scene nodes and the script must have the same name as the scene node and be right next to the scene node in the file system.

[SceneTree]
public partial class MyScene : Node2D 
{
    public override void _Ready() 
    {
        // You can access the node via '_' object.
        GD.Print(_.Node1.Node11.Node12.Node121);
        GD.Print(_.Node4.Node41.Node412);

        // You can also directly access nodes marked as having a unique name in the editor
        GD.Print(MyNodeWithUniqueName);
        GD.Print(_.Path.To.MyNodeWithUniqueName); // Long equivalent
    }
}

InputMap

From anywhere type InputActions.(...) to access both built-in and user defined actions defined in project.godot. For example InputActions.MoveLeft.

Clone this wiki locally