As part of a build process I am trying to separate parts of a max model into separate asset bundles.
I have a GameObject that has lots of children that are game objects lets say 20+, i want to take 4 of those child GameObjects detach them from there shared Parent and Parent them to a new GameObject that i have just created.
Ive tried just assigning the objects parent to a new object but this fails at runtime as its read only.
instance.m_gameObj.transform.parent.gameObject = newGO;
So i think i need to either make a copy of the child and add it is as a new component to my new GameObject.
And possibly even destroy the original parent object, but im worried that will destroy all the other child objects i want to copy over as well as there still attached to it.
* Update *
What ive tried since posting.
- Use EditorUtility.InstantiatePrefab to create clones of the 4 game objects i want
- Then use UnityEngine.Object.DestroyImmediate to destroy each game objects parent
- Then create a new dummy game object like this - `GameObject newGO = new GameObject("MainAsset");`
- Then make the parent of my 4 game objects the new dummy game object `m_gameObj.transform.parent = newGO.transform;`
- Then build the asset bundle of the new GameObject - `bool buildOk = BuildPipeline.BuildAssetBundle(newGO, null, bundleTarget, BuildAssetBundleOptions.CollectDependencies);`
- But still no luck even tho there is no crashes or warnings the BuildAssetBundle returns false, and im still trying to work out what part of this its not liking.
Does anyone have any ideas for this?