Fastest way to spawn a new mesh from a source stored in memory

Hi,

With the idea to spawn meshes in real-time (E.g. to create new enemies in the middle of a stage in a game).

From the point of view of performance:

  • Is unserializing a mesh fast enough as to do it in real-time in the middle of a stage?
  • Or should I unserialize a mesh in the beggining of the stage, make it invisible, and clone it
    everytime I want to spawn a new mesh in real-time?

I’m not sure what would be the best way to store that source mesh in memory (which is going to be used to create the new ones), and then clone everytime I want to spawn a new one.

The first approach I’m thinking is to import a mesh, make it invisible, and then clone it every time I need to spawn a new element.

Using instances could be a good way, but I want give to the users the possibility to customize each element mesh: Mesh instances. Maybe one enemy can have a glow built by shader, or other can modify its mesh because an impact.

Speed wise: it would be better to have a “stock” of meshes that are disabled that you clone or instantiate depending on your needs

1 Like

How can I disable a mesh? Is it setting isVisible to false?

mesh.setEnabled(false)

1 Like

My eternal problem of diagonal reading :smiley:
Thanks!

2 Likes