Create a clone without components at runtime
Hi,
how can I create a clone of my GameObject at runtime, but without any "Behaviour". Let's say I have a helicopter, with lots of components that do their own job: rotate the rotor, fly, control the canon, take hits, consume fuel, Colliders, Rigidbodies, etc. Now I want to create a "Ghost" that only shows a position. The ghost does nothing except being blue and semi-transparent.
So I figured I call GameObject clone = Instantiate(myActualHelicopterGameObject)
, and then do a foreach(var component in clone.GetComponentsInChildren<Component>(true))
where I call Destroy(component)
for every component that has nothing to do with mesh rendering, and assign a ghostly material.
But now I get a ton of errors because all components depend on each other because of RequireComponent.
What is the good way of creating such kind of ghost clones at runtime?
maybe best way is not duplicate the existent object, I mean, maybe is better to instantiate a new empy GameObject and attach only the mesh component.