Exploder and pooling objects

0
AndyGFX posted this 10 May 2015

Hi,

would be good have option to return back modified volume (i.e. when Exploder is applied) or hide voxel instead remove, because when volume prefab is used in pool manager, then is again used later and is modified from previous behaviour.

AndyGFX.

9 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 03 June 2015

I'm thinking of making a script to do this actually. It'll just be a simple script you can attach to a Volume that will "remember" the initial state of the voxel array and copy it back over with a function call. Nice and simple.

The reason the original voxel array is not already stored is simply that it would require twice as much RAM per volume to store the initial state. I could simply make it a per-volume option to keep the original data.

0
AndyGFX posted this 03 June 2015

Hi,

addtitional component is very good solution because not all scene objects are dynamic.

Andy.

0
Squize posted this 15 July 2015

Hey,

Firstly, thanks for the great package, it's been a huge time saver when using magicaVoxel files ( Updating loaded files would be fantastic, but I've seen the reasons why it's not straight forward in another thread )

I just want to back up Andy's feature request here as I've hit the same issue, pooled baddies are coming back in their exploded state. I'm guessing each Frame is pretty much a container for the Chunks, so the data is there to be pulled out and saved, any pointers about the best way to do that ?

Cheers,

Squize.

0
Squize posted this 15 July 2015

I've managed to come up with a workaround ( It's always the way, as soon as you post asking for help... )

        voxels = gameObject.GetComponent<volume>(); 

    int XSize = voxels.XSize;
    int YSize = voxels.XSize;
    int ZSize = voxels.ZSize;

    voxelStorage=new Voxel[XSize * (YSize * ZSize)];

    Voxel voxData;
    for (int y = 0; y < ysize;="" y++){="" for="" (int="" x="0;" x="">< xsize;="" x="" ++){="" for="" (int="" z="0;" z="">< zsize;="" z++){="" voxdata="voxels.Frames[0].Voxels[x" +="" xsize="" *="" (y="" +="" ysize="" *="" z)];="" if="" (voxdata.active="=true){" voxelstorage[x="" +="" xsize="" *="" (y="" +="" ysize="" *="" z)]="voxData;" }="" }="" }="" }="" so="" we="" call="" that="" during="" awake="" to="" store="" all="" our="" voxels="" away="" (="" voxelstorage="" is="" just="" an="" array,="" private="" voxel[]="" voxelstorage;="" )="" on="" the="" baddie="" killed="" we="" just="" shove="" it="" all="" back,="" int="" xsize="voxels.XSize;" int="" ysize="voxels.XSize;" int="" zsize="voxels.ZSize;" voxel="" voxdata;="" for="" (int="" y="0;" y="">< ysize;="" y++){="" for="" (int="" x="0;" x="">< xsize;="" x="" ++){="" for="" (int="" z="0;" z="">< zsize;="" z++){="" voxdata="voxelstorage[x" +="" xsize="" *="" (y="" +="" ysize="" *="" z)];="" if="" (voxdata.active="=true){" voxels.frames[0].voxels[x="" +="" xsize="" *="" (y="" +="" ysize="" *="" z)]="voxdata;" }="" }="" }="" }="" voxels.frames[0].updateallchunks();="" it's="" not="" pretty="" and="" could="" do="" with="" some="" optimisation,="" but="" it's="" working="" for="" my="" fairly="" simple="" needs,="" so="" i="" thought="" i'd="" share="" before="" the="" official="" solution="" comes="" out.="" cheers,="" squize.="" zsize;="" z++){="" voxdata="voxelStorage[x" +="" xsize="" *="" (y="" +="" ysize="" *="" z)];="" if="" (voxdata.active="=true){" voxels.frames[0].voxels[x="" +="" xsize="" *="" (y="" +="" ysize="" *="" z)]="voxData;" }="" }="" }="" }="" voxels.frames[0].updateallchunks();="" it's="" not="" pretty="" and="" could="" do="" with="" some="" optimisation,="" but="" it's="" working="" for="" my="" fairly="" simple="" needs,="" so="" i="" thought="" i'd="" share="" before="" the="" official="" solution="" comes="" out.="" cheers,=""></volume>

0
Squize posted this 15 July 2015

Ha, well that formatting broke a treat, sorry

0
GarethIW posted this 17 July 2015

Oh wow, that did break didn't it?

But yes, you're on the right lines from what I can tell. You should be able to use Array.Copy though, instead of iterating over the array. Should be faster, and you'll need all the speed you can get when re-activating on the fly. Also, try using UpdateAllChunksNextFrame() so that the mesh rebuild is threaded, although without trying it I can't say if it will be better or not than a simple UpdateAllChunks().

I've been thinking about this a little, and I think I've decided to implement this in future versions by changing the voxel Active flag to a byte enum with a status of Active, Hidden or Inactive.

Exploding will change the state to Hidden and will then be treated as if it was Active=false, until you call a method to rebuild the volume which will set all Hidden voxels back to Active and regen the mesh.

0
Squize posted this 20 July 2015

Thanks for the reply mate ( And fixing my post, I really don't know what happened there ).

Yeah I was a little concerned about rebuilding the Volume post death, some great tips there thank you I'll have a play around and see what works best ( And yeah, loving the Hidden idea )

0
Pixellore posted this 25 October 2015

Just curious, is this "hiding and then rebuilding" has been officially been implemented?

0
GarethIW posted this 25 October 2015

As of 1.4.0, this has been implemented. You can reset all destroyed voxels using Frame.Reset().


Our 125 members have posted 459 times in 111 discussions