- Home /
Instantiate not duplicating ScriptableObject hierarchy
So, after fiddling with assets for a while (.asset files), I rewrote the internals of an editor script to generate a prefab instead. I thought it would make it properly duplicate the full object hierarchy, whereas assets were simply ignored most of the time.
Now, in the prefab in the project view, the hierarchy looks correct, i.e.:
Prefab ->ScriptableObject(s)
But whenever I run an Instantiate on this prefab, it only instantiates the Prefab - all ScriptableObject assets are not instantiated but seem to be accessed the same from every single prefab instance. This is the exact problem I was hoping to fix with the prefab rebuild of the system.
So, the question is, how can I force it to instantiate the full prefab?
Illustration: 
Hey, wait, it sounds like you've managed to solve a problem I've been banging my head against - How did you get the Scriptable Objects baked into the Prefab in the first place?
By mixing AssetDatabase commands and PrefabUtility commands. This is how it looks in C#:
Pattern pattern = (Pattern)ScriptableObject.CreateInstance( typeof( Pattern ) );
AssetDatabase.AddObjectToAsset( pattern, m_Container );
EditorUtility.SetDirty( m_Container );
AssetDatabase.AddObjectToAsset adds the scriptableobject (pattern) to the prefab object (m_Container) as a child.
But the problem, I think, is that assets aren't handled the same way as prefabs. So even though it's saved into the prefab - and can be retrieved by the same editor script later - it doesn't actually instantiate with the prefab, because it's technically not part of it.
Extremely frustrating, but I think what I'll have to do is convert the ScriptableObject scripts into $$anonymous$$onoBehaviour and add child GOs ins$$anonymous$$d.
That's what I'm looking at - It got into my head that you can't have more than one $$anonymous$$B of the same type on the object, but I think that's false. Tricky bit is then the editor, so it's either find a way to hide the display of a thing on the pane, or stick everything on a managed child object.
Your answer