Exploder script slow

0
arknano posted this 18 January 2017

So I've been intending to use the Exploder to, well, explode things, but I've noticed that Unity freezes for a time every time it's triggered, regardless of the number of voxels in the volume(s) affected. I've observed this behaivour in the sample projects as well, so I'm fairly sure it's not a problem with my implementation.

My PC isn't amazing (i5 2500, GTX 960), but I don't imagine this behaivour is the norm on lower end hardware with barely a dozen voxels.

Just wondering if this is known or perhaps something on my end that I can fix? Thanks for your time!

Last edited 18 January 2017

1 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 18 January 2017

Several things:

1) Editor performance.

C# scripts run waaaaaay slower in the editor. You wouldn't notice it for simple scripts, but for something as complicated as meshing, you will. Try it in a build.

2) You're exploding too many voxels.

What's the sort of radius you're trying to destroy compared to the size of the voxels?

I don't know if you're familiar with Minecraft at all, but I often use that as an analogy to try to explain. TNT in Minecraft has an explosion radius of about 7 blocks.

In Picavoxel, if you set a radius of 2 on the exploder script, and are using a default size of 0.1 units per voxel, that is a radius of 20 voxels, around 3 times the size of a TNT explosion in Minecraft.

To explain it in more detail, using the above values of an explosion radius of 2 and a voxel size of 0.1, the total number of chunks affected can be anywhere up to 16 (40^3 voxels explosion volume divided by 16^3 chunk size). That means that we need to recalculate the meshes of 16 chunks, which is quite expensive.

3) Meshing Mode. 

Greedy meshing takes more time to calculate than simple culling. Try switching to culled mode for your explosion target volume. When optimizing your game, you'll need to balance between triangles rendered and the need for volumes to explode.

4) The out-of-the-box exploder script.

The exploder script is good for getting up and running with explosions quickly, but it does have the limitation that it checks for explosions against all volumes in the scene. In your own games, it is never likely that you would need to do this and would instead be checking for explosions on a specific volume or set of volumes, at a specific location. In this case, you can simply call Explode on the Volume class. For example:

wall.GetComponent<volume>().Explode(bullet.position, 0.5f, 0, Exploder.ExplodeValueFilterOperation.GreaterThanOrEqualTo);</volume>


Our 282 members have posted 390 times in 91 discussions