Try to make a plugin, a custom node with a .tscn

Godot Version

4.3

Question

I want to make a plugin, a custom node with a .tscn but it doesn’t work
1

  1. I change the Size value of my custom node
  2. IDK why but the .tscn of the node change
  3. The size of the 2 nodes changes at the same time

Plugin.cs :

#if TOOLS
using Godot;
using System;

[Tool]
public partial class Plugin : EditorPlugin
{
    protected const string WP3D_NODE_NAME = "WayPoint3D";
    protected const string WP3D_ICON_PATH = "res://addons/way_point/src/assets/icon_3d.svg";
    protected const string WP3D_SCRIPT_PATH = "res://addons/way_point/src/3d/WayPoint3D.cs";

    public override void _EnterTree()
    {
        Texture2D icon3D = GD.Load<Texture2D>(WP3D_ICON_PATH);
        CSharpScript wp3dScript = GD.Load<CSharpScript>(WP3D_SCRIPT_PATH);
        this.AddCustomType(WP3D_NODE_NAME, "Node3D", wp3dScript, icon3D);
    }

    public override void _ExitTree()
    {
        this.RemoveCustomType(WP3D_NODE_NAME);
    }
}
#endif

WayPoint3D.cs :

#if TOOLS
using Godot;
using System;
using System.Runtime.CompilerServices;

[Tool]
public partial class WayPoint3D : Node
{
    protected const string WP3D_TSCN_PATH = "res://addons/way_point/src/3d/WP3D.tscn";

    [Export(PropertyHint.Range, "0.01,100")]
    public Vector3 Size { get; set; } = new Vector3(1, 1, 1);

    public override void _EnterTree()
    {
        if (Engine.IsEditorHint())
        {
            WayPoint3DModel wayPoint3DModel = new()
            {
                Size = this.Size,
            };

            PackedScene pcked = ResourceLoader.Load<PackedScene>(WP3D_TSCN_PATH);
            WP3D wp3d = pcked.Instantiate<WP3D>();
            this.AddChild(wp3d);

            ((GetChild(0).FindChild("Shape") as CollisionShape3D).Shape as BoxShape3D).Size = wayPoint3DModel.Size;
        }
        base._EnterTree();
    }

    public override void _Process(double delta)
    {
        if (Engine.IsEditorHint())
        {
            WayPoint3DModel wayPoint3DModel = new()
            {
                Size = this.Size,
            };
            (GetChild(0) as WP3D).UpdateSize(wayPoint3DModel.Size);
            // ((GetChild(0).FindChild("Shape") as CollisionShape3D).Shape as BoxShape3D).Size = wayPoint3DModel.Size;
        }
        base._Process(delta);
    }

    public override void _ExitTree()
    {
        if (Engine.IsEditorHint())
        {
            this.GetChild(0).QueueFree();
        }
        base._ExitTree();
    }
}
#endif

WayPointModel.cs :

using Godot;

public partial class WayPoint3DModel
{
    public Vector3 Size;

    public WayPoint3DModel() { }
}

WP3D.cs :

`#if TOOLS
using Godot;
using System;

[Tool]
public partial class WP3D : Node3D
{
    [Export]
    public CollisionShape3D CollisionShape3D { get; set; }

    public void UpdateSize(Vector3 newSize)
    {
        (CollisionShape3D.Shape as BoxShape3D).Size = newSize;
    }
}
#endif

If anyone know what I do wrong please help me :blush:

in every frame

you do this:

this is not 3D node

but here is?

I think is good class for be resource

You’re right in concern of the WayPoint3D is not Node3D I’ve changed that.
But “WayPoint3DModel” and “WayPoint3D” are not the same.

Current :
I add WayPoint3D.cs to my custom type, now it’s for instantiate a .tscn named WP3D.tscn (IDK if I’m in the truth)

Did you try make Global Class instead CustomType? most custom node/resource classes accessed in editor mode, needed have Tool or will work like build in classes.


Any Node can have custom icon with
[Icon(“res://…”)] like this:

[Icon("res://addons/way_point/src/assets/icon_3d.svg")] 

you can combine attributes like this:

[GlobalClass, Icon("res://addons/way_point/src/assets/icon_3d.svg")]