godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine

Home Page:https://godotengine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get to the script (C# object) instance from EditorInspectorPlugin code

Servail opened this issue · comments

Godot version

4.1.rc3.mono.official [cdd2313]

System information

N/A

Issue description

Looks like EditorInspectorPlugin's virtual methods (_CanHandle() _ParseBegin() _ParseEnd() etc.) GodotObject parameter (@object) doesn't relate to C# script class instance at all.
In my other issue I realised that when you attaching a script to Node or Resource (which are GodotObjects), it kind of becomes the Type of that script (class).
Also according to this answer I just must cast GodotObject to the script Type. But it fails!
Maybe I'm being stupid (again?), but how to get to the "real" instance?

Steps to reproduce

  1. Open attached project
  2. Look in TestInspectorPlugin.cs
  3. Press "TEST" button in inspector
    Checked everything I can think of; must print C# script class type somewhere, but don't!

Minimal reproduction project

TestProject.zip

I found it starts working as intended only with [Tool] attribute added to TestScript or TestResource! I think it's because C# class is not actually instantiated in editor by default. Then how Godot gets to script object's fields and serializes values?