Hi,
I created a script with a serialized field in where I dragged and dropped a gameobject and I’d get its rect transform, like this:[SerializeField] private RectTransform parentPanel = null;
For sure it works
The problem I got is when I try to do the very same thing with scriptable objects. The code is exactly the same, however I simply cannot select any gameobject (Editor “Parent Panel” field is None, no gameobjects are nor selectable neither dropable).
What am I exactly doing wrong? What am I missing?
You cannot reference objects in a scene from an asset (like a ScriptableObject saved in the Assets folder).
This is both a restriction in the serialization system (it doesn’t know how to reference parts of a scene from outside that scene), and a logical restriction (what would it mean to try to access an object in a scene when that scene isn’t open).
I have a set of scriptable objects called gameState that update some elements within a scene. I want them to dynamically generate/destroy several gameobjects (UI related) whenever a the current gamestate changes, and so I wanted to provide the position where they shall be created at.
@Ifridos as Baste said: Simply change the direction of the dependency. Reference the prefab instead of the gameObject in the scene and instantiate whatever you have referenced. That works.
@Ifridos , We use that widly throughout the project. The ScriptableObject provides the references to the prefabs, the instantiation object gets a reference to the scriptable object.
Drag the prefab from the project view directly on your public or [SerializeField] GameObject (or Component Type) reference. That definetly works.
I still couldn’t drag&drop it until after restarting the computer, not even restarting the editor would do it (which is what I tried before opening this thread).
Thank you all.