I’d like to re-parent a Component, or to clone an existing Component and attach it to some other GameObject.
I have tried GetComponent<T>().transform.parent = myNewParent.transform
but this will not work because the documentation says transform
is the parent GameObject’s transform.
Looking at GameObject.AddComponent(...)
, I can only pass in a type, not an existing instance of a Component.
Is it possible to re-parent a Component and if so how?
Short answer is: No!
The owner of a component can’t be changed.
I dont think you need to move it.
If you know what Component you want. You can just ADD it to the GameObject you want.
If you need the values equal, you can make a simple script that copies those after adding the GameObject.
The GameObject
http://unity3d.com/support/documentation/ScriptReference/GameObject.html
Add Component
http://unity3d.com/support/documentation/ScriptReference/GameObject.AddComponent.html
Alternatively you can turn off the object’s mesh renderer, and collider, until the particle cycle finishes; then, destroy the object. -TE
After 3 years, is there any other viable solution other than reinstancing all components on the target GameObject and restoring their values?