Search Unity

Mobile 3D multiplayer top down shooter bullets - Instantiate,objectpool or particle system?

Discussion in 'Game Design' started by kot2202, Jun 25, 2020.

  1. kot2202

    kot2202

    Joined:
    Aug 15, 2018
    Posts:
    5
    Which should I go with? Performance wise especially. There will be simple different weapons for example pistol; shotgun with 3-5~ projectiles where each separate projectile can trigger separate damage; rocket launcher(although this one will be objectpool, I'm pretty sure). Players seeing other players shooting will be pretty important (although maybe limit the visible things if its possible?)
    Can multiple projectiles from weapons like shotgun even be reliable with particle system?
     
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Just make your own. It's super simple and there's a great unity official tutorial on it.

    I had bought a few years back and they were all more of a hassle than just doing the code myself.

    Also, you really need to know how to do pools if you want to make games. It's just that simple.

    Quick tip though, circle and sphere colliders are stupid cheap.

    If you're using a mesh collider, give it a circle or sphere collider around it that toggle the more complicated collider.

    EDIT: and make sure that your colliders only check what they need to!!!
     
    kot2202 and Martin_H like this.
  3. kot2202

    kot2202

    Joined:
    Aug 15, 2018
    Posts:
    5
    Thanks for reply, but it was more of a question which one should I go with to get the highest performance possible and not have to redo them later when my game starts to lag. I have 45+ ~ fps in singleplayer with occassional instantiate spikes caused by getComponent called on Start(). I'm not even halfthrough the development and I'm getting bit worried already. I don't have any problem creating Instantiate ones, they are pretty simple but I read they are killing the unity's garbage collector, yes I am using timed Destroy() on them.
    Matches are fast paced but will take around 3-10~ min max, multiple things flying around and someone lagging in combat may really get annoying.
    So I'm between the choice of activating/deactivating particle system and object pooling which I know 0 about YET. I would like to hear about possible advantages and disadvantages of both. I will try to learn object pooling if it means better performance.

    Also, are sphere colliders faster than box ones?
     
  4. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    I never thought about using a particle system for bullets, so I can't speak to that.

    An object pooler is a great way to improve performance if you're instantiating hundreds of bullets at runtime.

    One gotcha with object pooling is that because you're reusing the same object, you might have to reset some variables on the scripts if you have them. E.g. reset the health to maximum or the rigidbody velocity to 0.
    Basically anything that you do in Start() and anything that changes over time might need to be reset in the OnEnable() function.

    If you're really concerned about performance, you should look into using the Profiler.

    You will be able to see exactly what's causing your lag spikes or low fps in general.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I created a networked object pool system for cannonballs in my current multiplayer project. I'm not exactly sold on the benefits of such a system, unless you are actually seeing stutters from all the bullet prefab instantiations. You add more network sync overhead when clients connect, since you need to sync all the pooled bullets, and it is a bit more work coding the resetting of the pooled objects (on both server and all clients) and activating/deactivating them than if you just instantiate/spawn new ones on the server.

    I have no experience using particle systems for projectiles (though actually I plan to when I add grape shot, but don't know what the pitfalls are yet).

    As far as your current issues, I'd just remove all those GetComponent calls in Start. If they are for other components on the same object, I had the same issue when spawning my ships as they have lots of components which need to talk to each other. I addressed it by creating another component I call ShipComponents, which has inspector references to all components on the object, and every script of mine on the same object has an inspector reference to ShipComponents. Almost eliminated GetComponent calls in Start by doing so, which got rid of any stutter I was seeing when they spawn in.
     
    Last edited: Jul 20, 2020
    kot2202 likes this.
  6. j4ke

    j4ke

    Joined:
    Dec 9, 2018
    Posts:
    21


    I had quite similar project but in singleplayer. The bullets are made with particle system and with particle collisions. There was no need for object pooling, except for the enemies, and this kind of bullet system runs well.
     
    kot2202 likes this.