• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Particles causing extreme vertex batches/texture swaps

Kyon

Member
Hi everyone, I just noticed, when I draw the bow in my game, the vertex batches/texture swaps increase a lot!
The only thing I can think of is that it's creating particles ( the circles around the bow ) when you do that.
Could that be it? and why? And how to fix?



Here is a gif where the 'problem' can be seen. On the left top you have the debug overlay with the vertex/texture swap and you can see it increase when I charge the bow.
( i know the gif is almost unwatchable but couldnt make a better one, ignore the green flashes, its the gif-make program )


Kyon.
 

Micah_DS

Member
Are you doing any of the following things with those particles?
There are a number of things that will break the batch, with the main ones being blend modes, setting the draw colour, setting the draw alpha, and drawing the built in shapes and primitives.
Source.

If you can create your own particle system via an array or something, then draw sprites based on positions stored in the array, you can avoid the batch breaks.
I expect there are easier/better/other solutions, but that's just what I did when I had a similar issue with a particle system of mine. My batches went up from 3 to 85+ before I did that, but now they remain at 3 when the particles are active.

For the record, I haven't used the built-in particle systems, so maybe that's a better way to go, I just don't know if that's what you're already doing and that maybe the particle system breaks batches or something. That's why I just recommended what I know to work.
Good luck!
 
Last edited:

Kyon

Member
Are you doing any of the following things with those particles?

Source.

If you can create your own particle system via an array or something, then draw sprites based on positions stored in the array, you can avoid the batch breaks.
I expect there are easier/better/other solutions, but that's just what I did when I had a similar issue with a particle system of mine. My batches went up from 3 to 85+ before I did that, but now they remain at 3 when the particles are active.

For the record, I haven't used the built-in particle systems, so maybe that's a better way to go, I just don't know if that's what you're already doing and that maybe the particle system breaks batches or something. That's why I just recommended what I know to work.
Good luck!
I was happy when you posted this and I thought maybe that was it. Because I ám changing the color of my particles constantly.
But. I removed all code that does this, and it still happens.
When I remove the particle creation the batches stay around 15, so it's definitely something with the particle system. :(

I also removed anything that changed the direction or the speed of the particles but nothing worked..
Ugh, I hope I dont have to make my own particle system haha.
 

Azenris

Member
are you using the inbuilt particle sprites for the particle type ( part_type_shape ), I think that breaks batches, use a custom sprite

EDIT: ops, someone already mentioned this :(
 
Last edited:

Micah_DS

Member
are you using the inbuilt particle sprites for the particle type ( part_type_shape ), I think that breaks batches, use a custom sprite
EDIT: ops, someone already mentioned this :(
If you're talking about me, I actually suggested something more involved outside of the particle system functions, so your suggestion is probably exactly what @Kyon needs, hopefully.
You're saying to use part_type_sprite(), right? That could very well be a solution, since it appears all 'shape' type drawing breaks batches. As long as there's no fancy blend mode being used as well, I bet that will work.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You're saying to use part_type_sprite(), right? That could very well be a solution, since it appears all 'shape' type drawing breaks batches
They do break batches as each of the different chapes is actually held on a single texture page... Part type sprite is definitely the way to go.

I was happy when you posted this and I thought maybe that was it. Because I ám changing the color of my particles constantly.
But. I removed all code that does this, and it still happens.
Colour blending/changing is only an issue on HTML5 and even then only when WebGL is disabled. You can use the colour and alpha blend functions without penalty. However using an ADDITIVE blend mode will also affect batching...

Note that a few extra texture swaps for a few frames is no big deal normally... Unless your game is massive and is struggling to maintain 60fps then it may be better to have a nicer effect and a few extra texture swaps than to have an uglier effect and a few extra fps. ;)
 

NightFrost

Member
They do break batches as each of the different chapes is actually held on a single texture page... Part type sprite is definitely the way to go.
This may have been so in 1.4 (I can't remember) but GMS2 places all the built-in shapes on single page, starting with the same page your own sprites use. What I find more concerning is you apparently can't get rid of them if you want to put the ~200x300 pixel area reserved by them to better use.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
This may have been so in 1.4 (I can't remember) but GMS2 places all the built-in shapes on single page, starting with the same page your own sprites use. What I find more concerning is you apparently can't get rid of them if you want to put the ~200x300 pixel area reserved by them to better use.
Interesting... That's something that has changed then in an update as it wasn't like that to start with.
 

NightFrost

Member
Interesting... That's something that has changed then in an update as it wasn't like that to start with.
I noticed this just a few months back when I was checking how much texture page my sprites were using. The old system would almost be better. I don't use default particle shapes so there would be no batch breaks, and they wouldn't be causing batch breaks by taking up space on pages that I am using. (Judging by their placement in top left, seems out of all sprites GMS places them in first.)
 

Kyon

Member
Hi all,
thanks for all the replies.
I tried changing it to part_type_sprite already, even made it so that the particle was a 1x1 pixel. But even that didn't remove the issue.
Strangest thing is, I havent changed anything in that code or anything lately. But after restarting gamemaker the issue is gone?

I have this quite often and I think it has something to do with vector graphics.
I'm struggling with random issues for over 2 years now, made quite a lot of topic about them but they never really get solved.
And I want to say it's a bug but I can't really explain or recreate it.
What I notice a lot is that sometimes I play my game and it has around 1000fps and sometimes it can be between 200-400.
I depends on the day. Maybe something with how gamemaker makes texture pages for swf files?

Anyway, I'm glad it's gone. So far no ground-breaking issues with my current game.
I actually quit my last game because it caused too much random lag spikes.. Started on this project just to cool down. Turned into my "main game".

I really wonder, has anyone ever released a vector art game in gamemaker? (like a commercial/"big" game)
 

Kyon

Member
Whoa nvm, I just had a moment.
Ok so the texture swapping thing only happens when the player is near a torch. Which also uses particles.
So. It's not that the torch causes it. But if I use the bow AND I'm near a torch, then it doubles in textureswaps.
But, just being with a torch (or multiple torches) OR just using my bow without a torch nearby, nothing happens.


Odd?
 

Micah_DS

Member
I really wonder, has anyone ever released a vector art game in gamemaker? (like a commercial/"big" game)
Wandersong.

Whoa nvm, I just had a moment.
Ok so the texture swapping thing only happens when the player is near a torch. Which also uses particles.
So. It's not that the torch causes it. But if I use the bow AND I'm near a torch, then it doubles in textureswaps.
But, just being with a torch (or multiple torches) OR just using my bow without a torch nearby, nothing happens.


Odd?
Hmm, all I can think of is that maybe the bow graphics and torch graphics are spread over multiple texture pages, I guess?

I recommend using the debugger to check exactly what your 'Surfaces & Textures' contain in both situations.
Just in case you aren't familiar with it (or if anyone else reads this later and needs more info), simply run in debug mode, pause the game via the debugger, go to the graphics tab and hit the refresh circle in the lower right. The texture page thumbnails will show up then.
 

Kyon

Member
Wandersong.


Hmm, all I can think of is that maybe the bow graphics and torch graphics are spread over multiple texture pages, I guess?

I recommend using the debugger to check exactly what your 'Surfaces & Textures' contain in both situations.
Just in case you aren't familiar with it (or if anyone else reads this later and needs more info), simply run in debug mode, pause the game via the debugger, go to the graphics tab and hit the refresh circle in the lower right. The texture page thumbnails will show up then.
Yikes, did not know Wandersong was a gamemaker game.
Haven't played that one either but it's on my list.


Alrighty so I done what you said and this is what I see right at the moment where there are multiple textures on the screen:


Seems normal enough, all my images appear on one texture page which is fine.
all my .swf files aren't visible though.
I do believe that the particle of the torch is a vector sprite. That could be the cause, but still I wonder why it only occurs when also using the bow (and it's particles)


(as you notice on the left top, it's quite high again. Even reaches to 40 texture swaps when all particles are visible. around 13-15 is normal)



EDIT:
Changing the sprite of the torch to an non-vector sprite solved the problem.
Anyway, I'd prefer not to do this of course, it's not a disaster, but still.
Can someone explain why this is exactly happening?
So. it doesn't occur when there are multiple torches around. So the amount of particles is not the problem. But when adding other particles to the screen, it causes to swap textures a lot. (from 15 to even 40)
 
Last edited:

Micah_DS

Member
Hmm, you could always temporarily swap out the .swf sprites in question for regular sprites and test again to see if they truly are the culprit.
But I don't have any experience with .swf files, so maybe I should shut up at this point. I hope you solve the issue though.
 

Kyon

Member
Hmm, you could always temporarily swap out the .swf sprites in question for regular sprites and test again to see if they truly are the culprit.
But I don't have any experience with .swf files, so maybe I should shut up at this point. I hope you solve the issue though.
Ah yeah, I edited my last post. I actually did that and yes, that was the issue.
I still would like to know why exactly.

Thanks for all the help anyway! :)
 
Top