godotengine / godotengine/godot-docs
C# custom Node class dynamic creation issue
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Your Godot version:** V3.2.3.stable.mono.official
**Issue description:**
I was need to instanciate my custom node class dymanically using C#. On this page (https://docs.godotengine.org/en/latest/getting_started/step_by_step/scripting_continued.html) we have "Creating nodes" section that messed things up a little bit. So like it was shown here i just tried to create my class with constructor and attach it to scene tree. Here i got two issues:
1. After creating node dynamically i belive you should set it's owner like it's shown here https://github.com/godotengine/godot/issues/12456
2. If you create node with class constructor is does not work like expected in editor. You have no **exported fields**, also editor says node has no script attached. The right way to create instance of **_custom_** class should be loading it with _Godot.GD.Load()_ function, cast resourse to _Godot.CSharpScript_ and then call _.New()_ method on it:
```
using Godot;
CSharpScript scr = (CSharpScript)GD.Load("res://src/YourClass.cs");
YourClass inst = (YourClass)scr.New();
this.AddChild(inst);
inst.Owner = this;
```
I think this things have to be put in documentation for C# in this section https://docs.godotengine.org/en/latest/getting_started/scripting/c_sharp/c_sharp_differences.html
**URL to the documentation page (if already existing):**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.