Hey, all,
I’m trying to produce a little bit of code to test out a damage model on buildings for the game I’m doing. I have models of the building in various different stages of destruction, and I’m wanting to substitute the meshes in and out.
Problem being that, in order to do this, I’m having to assign meshes to holding variables in my scripts. These don’t seem to be allocated correctly in the scene, as when I swap them out, there’s a noticable delay in doing this.
I can’t just swap the models either, as I have scripts attached to the models to look after some housekeeping functions, and they all use the same texture, so I would just like to be able to substitute in the meshes, and it run smoothly.
Is there something I’m missing? Is there a quicker way to do what I’m trying to do?
Cheers,
SB
If I had to guess I’d say the delay is likely caused by the mesh being loaded mid-game. Try loading each mesh into a variable at start.
Yeah, that’s what I do already. Still get a delay, unfortunately. I suspect it’s because the mesh is being loaded into some kind of display list, which is causing the delay, but I’d still sooner avoid it.
Problem is mainly down to the fact that, because I have scripts attached to the models, I can’t just swap them out for models I have floating around the scene.
Any other ideas?
Can you post the code you are using to swap the meshes in/out? Some of the Mesh class’s “variables” are actually properties that execute code behind the scenes and can actually be quite time-consuming.
My guess the problem is the meshes still need to be uploaded to the ram, which is slow the first time.
What you could do is render the mesh once when the scene has loaded. To avoid the user flashing all sorts of models, you could display a loading message/bar while rendering them.