Search Unity

Concern about particles

Discussion in 'Scripting' started by Deleted User, May 24, 2018.

  1. Deleted User

    Deleted User

    Guest

    Main concern about particlesystems is about pooling objects. Since my game creates levels at runtime reading from an external file I have to pool things generically, isn't a problm with audio for example where I get cached sounds and pooled AudioSources where I just instantiate the source from the pool and throw the audioclip in it to play the sound, this way I can have a generic pool of AudioSources and be done with it.

    In the case of particles there aren't assets to be applied to an emitter and the particlesystem is a set of modules, so in order to pool the objects would need many pools for each effect that is gonna be used in the map which I think is a bit cumbersome as would require to pool way too many gameobjects for just that since I can't use a particle asset to apply to some renderer.

    So my idea was the cache my own particle class which is just the set of modules a system uses and apply the modules to the ParticleSystem that is beign instantiated from the pool. My concern is that this operation may be a bit too expensive i nterms of performance.

    Imagine this situation, the player is shooting with a minigun on a wall, each bulelt impact produce a ParticleSystem, on that point I grab the system fro mthe pool, place on the spot of the impact and then apply to it the modules the system has to emit and then play the emission. How bad performance wise this would be without knowledge of whats going on behind the scenes in the ParticleSystem, do anyone has better alternatives for this case scenario?

    Thanks.
     
  2. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
  3. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Personally, I do this by faking it. I also have guns that fire rapidly and I create a shower of sparks every time a bullet hits a wall. The spark shower is actually just an animated texture on a quad that I orient towards the camera. It also does things like random rotation around it's own axis, randomly selecting from a selection of textures, scaling up as time passes, and sliding the alpha level down. Since I only have one quad per impact, it's very efficient and I really can't tell that it's not a particle system during gameplay. Because it's so efficient, I can combine it with other billboard objects in the pool (like smoke) to create really nice effects.
     
  4. Deleted User

    Deleted User

    Guest

    Would playing the emission interrupt the previous one using this? I really didn't know about EmitParams, I'll have to study it a bit and see if I can take advantage of it, seems a nice solution.