playMaker

Author Topic: Bullet system [SOLVED]  (Read 7301 times)

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Bullet system [SOLVED]
« on: September 27, 2017, 12:00:13 PM »
Hi

Me again XD

One last question for now. I was just starting to look at the performance of my game.

Enemy’s shoot a lot of bullets (Bullet hell style)
I spawn my bullets and move them with translate, if they reach level border or player they are returned to the pool after a trigger event (bullets have collider and rigid body). 

Game runs at the moment at 330 frames. When I have a lot of bullets on screen this drops to 150/130.
I still need to add a lot of stuff so this worries me a little bit.

Question:
Is there a better way of handling bullets than pooling them and moving them individually by translate?

Is there a better way to check collision than the on trigger function?

I cant seem to find a tutorial or forum post that talks about how to setup a “bullet system” or a game with a LOTS of bullets on screen in general.
« Last Edit: September 28, 2017, 06:44:49 AM by agito1987 »

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Bullet system
« Reply #1 on: September 27, 2017, 05:58:55 PM »
Quote
Is there a better way to check collision than the on trigger function?

I normal use collision event for object which will hit other objects in high speed, for example bullets.

I don't know about the pooling system. I have never used that. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system
« Reply #2 on: September 27, 2017, 06:04:25 PM »
I recommend using Core Game Kit, it comes with an excellent pooling solution (Pool Boss) and it integrates with Playmaker neatly.

Second, get Uni Bullet Hell (it can be wired to use Pool Boss) and enjoy.

Third, are you packing your sprites? How many draw calls do you have?

Available for Playmaker work

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system
« Reply #3 on: September 28, 2017, 04:58:43 AM »
Hi

Right now I use for the pooling the pooler action I got from here:
Forum post: http://hutonggames.com/playmakerforum/index.php?topic=12941.0
Download: https://github.com/ergin3d/PlayMakerCustomActions_U5/tree/master/Assets/PlayMaker-Custom-Actions/Pooler

Would the Core Gamekit package give me a better performance compared to the script above?
And yeah I was already looking at unibullet. But wasn’t sure if I could use this together with playmaker actions. (Especially how the detection of the bullets works.

My draw calls are as followed with the background disabled (still need to combine my meshes and clean up):

Without background:
Batches 105
Set pass calls 75

With background at the moment:
Batches 225
Set pass calls 195

Everything is still not combined and a lot of rotation fsm’s gonna fix that after the bullets.

With 36 enemys that shoot 1 bullet every 3 sec:
Batches: 350 – 400
Set pases: 250

Not sure if it’s important to mention but I pool a lot I don’t use in the scene yet to advance stress test.
Enemy’s that are on screen and bullets are pooled as mentioned above.

I see the collision event2 action in the ecosystem. Is this more efficient than the trigger event? Because right now I use a LOT of trigger events in my FSM’s.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system
« Reply #4 on: September 28, 2017, 05:39:57 AM »
Oh no, that's a lot, you're not using sprite atlas definitely. I've got 20 set pass calls on a screen full of prefabs.

I recommend you this packer, it's simple to use and efficient: https://www.assetstore.unity3d.com/en/#!/content/12976

Use collisions for collisions, as the name states, use trigger for flythrough stuff, like bullets passing through multiple enemies.

I haven't used Pooler so i don't know how it fares compared to Pool Boss, but the cool thing about Core Game Kit is that it integrates pooling, spawning and my favourite, the killable module which you can use for defining attack/hit points, ignoring offscreen hits, invincibility settings, layer and tag filters, death timers, death prefabs, death variable modifiers and a lot more.

Unibullet hell also has the possibility to spawn bullets from the Pool Boss pool. It works great with Playmaker, let me know if you need any advice, i couldn't imagine making a shmup without these tools.
Available for Playmaker work

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system
« Reply #5 on: September 28, 2017, 06:10:46 AM »
Thanks!

I am not working with sprites XD everything is 3d.
However I use an orthographic camera for my game view… so maybe I should think about converting my enemy’s into sprites.

Gonna give the game kit and uni bullet a go. Will switch out most of my trigger events for collision and will give everything in its whole a good clean up and I will see how far I come with this.

I wil keep this for now as solved. Would be great if you could bookmark this post should I need some more advice. :P ;D

And it’s not a traditional schmup. I have a player that rotates around a planet. Enemy’s are round the planet, and rotate around it. So I have more in the scene going on than only the traditional square as normal. The opposite site of the level is not in view but still active.
Anyhow, thanks for the great advice, now I know what to work on!

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system [SOLVED]
« Reply #6 on: September 28, 2017, 12:47:08 PM »
Ok I got “uni bullet hell” and “core game kit”.
Core game kit is great!
However uni bullet hell I don’t quite understand.
The 2d example only has a handful of batches 1 for every object. So when you play with background there are 14 batches.
But when I check the uni bullet example 3d with 300 + pooled bullets on screen (3d spheres), the batch count goes up to 300. So its the same problem as I was having.
Does this mean that unity no matter if I am pooling or not needs 1 draw call for every 3d object? Even though it’s the same prefab with the same materials?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system [SOLVED]
« Reply #7 on: September 28, 2017, 02:34:45 PM »
Pooling does not solve the problem of draw calls, but don't think you bought it for nothing! As you know, pooling eliminates hiccups caused by instantiation and is absolutely necessary to have a good solution to provide a smooth gameplay with high frame rate.vYou will see the good sides of using core game kit and unibullet hell together when you get a bit deeper into development of the game.

The thing with draw calls is it doesn't matter if you have 300 absolutely same prefabs with same textures, it will make a pass for each of those objects. With texture atlas for sprites it is solved by simple referring to the location of the needed sprite on the atlas.

Texture atlas can also be used for 3d textures, you need to combine multiple textures for different objects in a single sprite sheet.

I don't work with 3d, but i've been reading a lot about it out of curiosity, so i recommend you to check these out:

https://docs.unity3d.com/Manual/DrawCallBatching.html

http://answers.unity3d.com/questions/14578/whats-the-best-way-to-reduce-draw-calls.html
Available for Playmaker work

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system [SOLVED]
« Reply #8 on: October 05, 2017, 04:17:37 AM »
Ok I got everything working. Especially the killable option in the core game kit simplifies a lot!
Now I can use the killable component instead of a super complicated fsm with all the different damage types XD.

However. I have a problem with the unibullet system. How did you solve the despawning of the bullets?

I asked in the forums for a solution and got:
“Please call "UbhObjectPool.instance.ReleaseBullet (ubhBullet)" method when returning Bullet to pool.” (I only use playmaker so this is a problem XD)

The killable despawns the bullet to the bosspool. But the unibullet takes it out and places it in its own list.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system [SOLVED]
« Reply #9 on: October 05, 2017, 05:06:30 AM »
Yeah Nishioka is not quite good with english. I asked him the same thing long ago, here's his answer:

Quote
Only it has set the bullet of the parent to UbhObjectPool.
Instantiate has been done in PoolBoss.

Are you sure it "takes it out"? Does it first appear in the Pool Boss, then in UBH pool?

Edit: Hmmm, now i see your post on unity forums, i'll check it out on my side.
« Last Edit: October 05, 2017, 06:00:35 AM by krmko »
Available for Playmaker work

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system [SOLVED]
« Reply #10 on: October 05, 2017, 06:10:02 AM »
Well yea it works in 2 ways. When I first setup a poolbos pool it takes the bullets out and puts them into UbhObjectPool.

When I don’t create a poolbos pool it dynamicly creates the bullets inside of its own UbhObjectPool.

So when despawning with killable it is put back into the poolbos pool. And taken out by UbhObjectPool as long as its in the scene.
And it works! Only problem are all those cautions that keep piling up saying “This bullet is already added in m_bulletList.”

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system [SOLVED]
« Reply #11 on: October 05, 2017, 06:12:38 AM »
Oh yeah, i've got the same error. Let's see what the method does.
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system [SOLVED]
« Reply #12 on: October 05, 2017, 06:29:39 AM »
As far as i can tell, ubh bullet script is instantiated on bullet itself on runtime upon firing and the method Nishioka mentions is used for returning the bullet to the pool when using autorelease.

Since it's already despawned and returned to the pool boss pool it tries returning it from there to ubh pool, but it reports that it's already there.

If he's already advertising the product for using Core Game Kit's pool, he should make it work with killable component without warnings.

I'll write on unity forums too, he really ought to fix that. Sure, all works well, but still.

Here's the method that displays the debug warning:

Code: [Select]
public void AddBullet(UbhBullet bullet)
    {
        if (m_bulletList.Contains(bullet))
        {
            Debug.LogWarning("This bullet is already added in m_bulletList.");
            return;
        }
        m_bulletList.Add(bullet);

So if Pool Boss is used, why the hell is it trying to add it to m_bulletlist?
« Last Edit: October 05, 2017, 06:33:04 AM by krmko »
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Bullet system [SOLVED]
« Reply #13 on: October 05, 2017, 06:42:06 AM »
Wait, everything is fine now, i was using old version of UBH and when i updated it i forgot to comment out #define for using CGK Pool Boos.

Did you do it?

Available for Playmaker work

agito1987

  • Playmaker Newbie
  • *
  • Posts: 37
Re: Bullet system [SOLVED]
« Reply #14 on: October 05, 2017, 06:53:33 AM »
Yea have done that… removed the 2 // marks on line 4.