Godot Version
4.3
Question
I want to make a plugin, a custom node with a .tscn but it doesn’t work
- I change the Size value of my custom node
- IDK why but the .tscn of the node change
- 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