- Home /
Building asset bundles and wanting to move game objects from one parent to a newly created parent
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?
Answer by Lucas Meijer 1 · Aug 31, 2010 at 01:46 PM
I cannot see from the information provided what is wrong, however, we created a relatively complex project that uses asset bundles extensively to show how to effectively use assetbundles in a real world scenario. (It also takes a fbx file, and creates different assetbundles from different subsets of the fbx file). You can find it at: http://unity3d.com/support/resources/example-projects/charactercustomization
Your answer
Follow this Question
Related Questions
How can I access a child object? 1 Answer
DontDestroyOnLoad with not marked parents bug? (steps to reproduce here too!)) 1 Answer
How to remove the GameObject having the Object 1 Answer
Instantiate Terrain Object as child of Empty Game Object 1 Answer
How to destroy a parent object when child object is collided 1 Answer