Hello everyone! I am coming to the community with a question I just can’t seem to find an answer to. What I am trying to do is have script C show the inspectors for script A and script B. I am trying to keep script A and B as separate files because they do different things, but have the user only need to drag script C onto a GameObject and get the fields for both script A and script B. Right now I am able to have script C require and assign script A and script B to their respective fields automatically, but how would I go about showing their custom inspectors in script C?
Sorry if this doesn’t make too much sense, this is the best way I could explain. I did include a picture showing sort of what I need to accomplish
I think OdinInspector and/or AdvancedInspector on the asset store just sorta does this anyway… if you have ScriptC with references to a ScriptA and a ScriptB, it fleshes it fully out in ScriptC by default.
OdinInspector doesn’t do it automatically (that would be annoying honestly), but it has an attribute called InlineEditor that can do what OP is looking for.
Wouldn’t know the actual editor code answer. Unity’s default property drawer scripting is something I pinged right off… so I use Odin myself.
Thanks for your answers, but I am not looking to solve the issue by purchasing an asset. I’m more looking to see how to do it myself. The way I see things, if those two assets can do it, then there shouldn’t be an issue getting it done without another asset involved. So does anyone have information that leans more towards what I’m trying to do? Thanks!
Link to zip containing project and files coming in a few minutes. Beware that it does not check for cross referenced instance fields (infinite inlining loops) because it was just to see what it was about (I always used my own inspector system and docking system).
In order for this to be just a little more than an experiment for fun I added dynamic inlined editable fields updates and replaced calls to Editor.CreateEditor() that require a Object.Destroy() with Editor.CreateCachedEditor() which do not have said requirement to avoid leaks (from what the doc says). Inlinings (but not inlined fields values) are now also cached. So this is a more serious starting point for those who want to play with that.
Updated the exemple.
It now work for any situation like mixed Inlined & non-inlined editors in conjunction with self-referenced and cross referenced references values. In other words if you add a little cosmetic sugar to it you can sell it.
Improved visuals (inlined components foldout and header)
Optimized code (the history now use a fixed array & the edited objects stack have been replaced by a simple counter + inlining caching/update now only performed for EventType.layout + shared string builder everywhere it’s applicable etc)
Fixed fields references values changes not being reflected the first time after a scripts reloading and fixed a potential memory leak (Unity doc say that cleaning editors created with CreateCachedEditor() is not necessary but i dont trust them).