Stutter on cloned dynamic meshes

I am making a game;

  1. I create meshes dynamically
  2. I then clone these meshes multiple times during a level of the game
  3. Cloning seems to be instant so doesn’t seem to be a problem doing this while the level is playing.
  4. However the new cloned meshes seem to stutter when they first become visible on screen.
  5. The stuttering is only when they first enter and does not continue.
  6. They are initially off screen for a period of time before coming onscreen - no stutter occurs until they are actually viewable onscreen.

Is there anything that happens when a mesh first comes onscreen that I need to “pre-load/build” ? I thought maybe shaders, but have tried to force compilation when the mesh is first cloned, but does not change anything (if I am doing it right).

Not sure how hard it will be to do a playground on this.

It seems to be related to shader compilation, but it’s hard to say without a repro (I don’t see anything except shader compilation that could explain a little delay when first displaying a cloned mesh).

Are you able to take a performance snapshot in Chrome when that happens?

I thought it must be shader compilation - so shaders are only compiled when the object comes onscreen, not when it is created?

I don’t seem to need to compile shaders on the clones (from testing).

The main shader is a node shader which I compile on startup and then clone whenever I need a new one.

If it helps here is my game as it stands now (testing version)
click ‘play’ and wait a few seconds for the objects to come on.

You can see the first time the big object comes on it stutters, then if you destroy that object (use the mouse like a finger on a mobile game), the same object comes on again, but no stutter.

Also I preload textures using the asset manager - I assume once they are loaded they aren’t reloaded.

I was able to do a performance snapshot in Chrome from your live link, and the stuttering definitely comes from the shader compilation.

Do you pass true for the shareEffect parameter of the NodeMaterial.clone() function? The value is false by default, which might explain why it stutters if you leave it false.

Worked! almost…
No idea why…

But all stutter gone except for a little minor one - I’ll try to figure out what that is - maybe another material I missed.

It was a single texture I forgot to pre-load. all fixed now! thankyou!

Have a related problem now - not sure if this is caused by the ‘shareEffect’ - I make the enemies flash when they are hit by animating a ‘brightness’ property on the node material on the meshes.

The problem is when I do this it seems to light up all the meshes, even the ones that aren’t hit…

What would be causing that?

You answered this in another post - the materials must be cloned along with the mesh - I’ve got it now.