Is it more performant to Instantiate something or parent?

I’m thinking of, for example, a breakable crate. I have two versions, the complete crate and a collection of pieces, each with rigid bodies attached to them. Is it more performant to make a Prefab out of the collection of pieces and instantiate it when the crate breaks or to make the collection of broken pieces a disabled child of the complete crate, and simply enable the child and destroy the parent when the crate is broken?

Any time you can avoid instantiating, as long as you have memory available, it is good to do so. In your specific case, the parenting/destroying would be better. Of course, the parenting is not necessary; it would only be an organizational tool. If the crate was going to be used elsewhere, it would be even better to just disable it and then enable it again later. Further, it’s even faster to just turn off components than it is to turn off an entire game object, so do that too, if you can.

Thanks Jessy, I had a feeling that it might be better to do it that way, but the docs on prefabs suggest doing it that way, so I wasn’t sure.

I think it might as well be parented. It needs to be in exactly the same position and orientation as its counterpart when I make the switch. I suppose I could match the transforms manually when I make the switch, but I doubt it will make much difference.

The whole thing needs to be disabled though, otherwise I’ll be needlessly rendering it. Even if I put it out of the scene bounds somewhere, the renderer is still needlessly checking if it’s in the view frustum every frame, so I may as well disable it until I’m ready to make the switch.

You shouldn’t parent objects that don’t need to be, because the engine has to compute their positions every frame. Granted it won’t be a huge (or even noticeable) difference, but there’s no point wasting calculations…

–Eric