Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: agito1987 on September 27, 2017, 12:00:13 PM

Title: Bullet system [SOLVED]
Post by: agito1987 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.
Title: Re: Bullet system
Post by: Rabagast 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. :)
Title: Re: Bullet system
Post by: Fat Pug Studio 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?

Title: Re: Bullet system
Post by: agito1987 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.
Title: Re: Bullet system
Post by: Fat Pug Studio 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.
Title: Re: Bullet system
Post by: agito1987 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!
Title: Re: Bullet system [SOLVED]
Post by: agito1987 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?
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio 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
Title: Re: Bullet system [SOLVED]
Post by: agito1987 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.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio 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.
Title: Re: Bullet system [SOLVED]
Post by: agito1987 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.”
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 05, 2017, 06:12:38 AM
Oh yeah, i've got the same error. Let's see what the method does.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio 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?
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio 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?

(https://s1.postimg.org/3yikn8jbv3/image.jpg)
Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 05, 2017, 06:53:33 AM
Yea have done that… removed the 2 // marks on line 4.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 05, 2017, 07:01:57 AM
I'm on remote desktop now, i'll check what could be the problem when i get home. I don't get no warnings, strange.
Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 05, 2017, 08:32:51 AM
Made a new project, empty scene with only a cube spawning bullets. Killable disables bullet after 3 sec.
Once every bullet is used the warning pops up. (So the warning is not displayed immediately.)
Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 06, 2017, 05:11:58 AM
Ok super weird…

Today I started the project again. Unibullet still takes the bullets from poolbos. BUT I don’t have any warnings?! Don’t get why it didn’t work yesterday and today it does.
Without me doing anything =/.

Still thank you for your time again  ;D
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 06, 2017, 10:09:21 AM
You should report that to the dev, i'm sure that should not be like that.
Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 10, 2017, 03:48:42 AM
Just an update.

Unibullet at the moment does not work with the killable function of Core GameKit.
The dev said he will look in to it and possibly add this functionality in the future.

If you write your own code you can work around it. If you are like me primarily a playmaker user that wants to use the Core GameKit and its killable function. You should wait till the asset implements this function.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 10, 2017, 04:56:27 AM
I'm sure he'll do it sooner or later, he's a good guy. I don't know, i'm still using it, it's much easier to use then bulletml for example.

But i don't know how does it not work with killable, if you put killable on bullet, it despawns and gets back to pool boss, right?

Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 10, 2017, 05:17:06 AM
Yes it works.

But this functionality is the reason for the warning once you have used all your bullets.
"This bullet is already added in m_bulletList"
Right now you need to call "UbhObjectPool.instance.ReleaseBullet (ubhBullet)" method when returning Bullet to pool.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 10, 2017, 05:22:25 AM
Hmm, that excessive loging can cause low performance, it's best to comment out the debug line until Nishioka sorts it out.
Title: Re: Bullet system [SOLVED]
Post by: agito1987 on October 10, 2017, 05:56:31 AM
Yeah that’s my problem now. I don’t know how bad this issue is? 
 
So, you think by disabling the debug line it would be still ok to implement unibullet right now in my project? 
 
My biggest fear is once everything is setup, that I need to replace it further down the line should it become a problem in the long run. Or that the asset will be updated and need to replace everything I setup. 
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on October 10, 2017, 06:27:56 AM
I don't think it will pose a problem. You can check it out by yourself, make a pool of, i don't know, 100000 bullets, and make them spawn and despawn in a period of minute or two and watch the profiler.

You should usually turn off some of the debug stuff that you don't need in the final build anyway.
Title: Re: Bullet system [SOLVED]
Post by: Fat Pug Studio on January 25, 2019, 06:19:38 AM
Hey agito1987,

i made some UBH actions:

https://github.com/Oshigawa/Playmaker/blob/master/UBHStartShotRoutine
https://github.com/Oshigawa/Playmaker/blob/master/UBHStopShotRoutine
https://github.com/Oshigawa/Playmaker/blob/master/UBHStopShotRoutineAndPlayingShot
https://github.com/Oshigawa/Playmaker/blob/master/UBHReleaseBullet

Makes things a lot easier, no need to set properties, call methods and releasing bullets work great with Core Game Kit, finally. The greatest thing is that you won't lose references because you're using get/set property.

I'll merge StopShotRoutine and StopShotRoutineAndPlayingShot in one action when i find some time.