My Scriptable Objects do not appear to exist in my Asset Bundles. I’m tracking down the information I think I need to make this work, but I haven’t found a clear set of instructions yet.
I have a Monobehavior Component that has a list of ScriptableObjects that, in turn, have lists of SerializableObjects (some of which do that again…). Everything serializes/unserializes just fine in the Editor, but doesn’t make it into the Asset Bundle. The component’s lists are the correct size, but filled with null references. Note that, in many cases, the inheritance is Foo : Bar : ScriptableObject
, and there are references both to other scriptable objects, and other game objects.
So - how can I get the serializations properly stored in and then loaded with the Asset Bundle?
Edit:
To be clear, the observed problem is that when I load the asset bundle into the app, when trying to ForEach(o => o.Thing())
on the list of scriptable objects, I get null reference errors. List is of the correct size, but filled with null. We then found a script to import an asset bundle back into the Unity Editor, and when inspecting those objects, null reference error are thrown on a similar line of code. My interpretation is that the serialization is failing, as this looks the the same as the problems I was having prior to resolving the serialization issues.
Edit 2: The consensus is that you want to turn the scriptable objects into assets, and then reference those. I am now confused and trying to answer the how (CreateAsset
or AddToAsset
and what path) and the where - where do I put this code so it’s activated and used when the object is turned into a Prefab / changes are applied?
Edit 3: My problem is actually resolved by using monobehaviors (I’d gotten it into my head that you can’t have more than one component of the same name on an object, but you totally can) - however, I’m going to continue poking at this until an answer is found for those of you who can’t just switch to a MB. To be explicit, inherit from MonoBehavior
rather than ScriptableObject
, and ScriptableObject.CreateInstance
becomes gameObject.AddComponent
(where gameObject
is an actual object).