Mirror Prefab without using cc.instantiate

Hi,

I’m wondering how I could have several mirrored prefabs from one instantiated prefab. I would not want to cc.instantiate every single prefab to an own duplicate of the prefab.

I know how to work with cc.NodePool, it is fast and good but still requires you to duplicate cc.instantiate.

Is it possible to Mirror an existing prefab and show it on the screen several times and have them run the exact same way?

This would be amazing. Thanks for your help!

What exactly are you trying to do? I have a hard time imagining why you can’t instantiate and assign the same properties to each instance.

I’m thinking performance here. I can instantiate, but I’m trying to optimize everything. I don’t need to have the prefabs be their own instances.

Imagine having 100 instantiated prefabs as own duplicates or having 1 instantiated prefab mirrored 99 times with the same result. cc.instantiate() isn’t the lightest function to run either, especially if your prefabs are heavy.

If I instantiate 100 duplicated of a prefab I can act on each duplicate separately (e.g. activate/deactivate a node in it or what not). If it would be a mirror of the same prefab everything would react to the change of one.

I’m not sure if this is possible in CC, but if it is it would be cool to know :slight_smile:

I don’t think you can just deep copy a node instance (and I think that would be heavy on performance too) since cc.instantiate probably needs to assign some hidden properties like id when it happens.

Without knowing your project I’d suggest asking why your prefabs are so slow to instantiate.

They are not slow to instantiate and I also use them currently from cc.NodePool to not have them instantiate when I want to use them. But they are still instantiated in the memory while they do not need to be, since they all act the same way anyway.

Maybe my question doesn’t make any sense, but I just feel this could improve performance and save up memory?

Ok, I think I get it. I don’t think you could save on memory this case unless you were to make a static sprite out of all the copies. How much memory does your current setup use?

Not that much, it’s not an issue, it’s pretty well optimized already. This was just something I could possibly further optimize it :slight_smile:

Ah, good. But remember https://xkcd.com/1691/
:wink:

1 Like

Haha, so true :wink: