Thank you for all of the help you've provided me along my GMS journey. This video especially has improved my workflow and game as a whole. I'd love a sequel to this video if there are any more tips you could share.
holy cats, I did not realize a function call in a for loop would check every single time. You just gave my game a pretty significant, easy performance boost!
Ofc it does :)... There would be no way for the interpreter to know if the return value of your function would be the same every time so the function call has to take place. If you have a function call in the assignement part for(var i = getMyValue() then it will only get called once though since the assignment only happens once.
By far the best Game Maker video I've ever seen. Great content and presentation. Narrated very well, great subtle video effects and snappy editing, coloring and presentation of the code is great, analogies are clever, just absolutely fantastic.
1:25 Common performance sinks: drawing sprites, collisions, amount of objects 1:53 Run the profiler if you are having performance issues 2:16 We want the fps shown to be as high as possible when in debug mode 2:41 What we can see in the profiler 3:31 Demo: increasing the number of instances in the room 4:35 Demo: adding collision checks 5:00 Optimisation Tip: instead of the bullet checking for collision with player, check a player's collision with a bullet instead. (100 checks vs 1) 5:37 Collision functions' limitations (like place_meeting and instance_place) 5:54 The limitations generally shouldn't be a problem if 3 bullets are seemingly hitting at the same time, since they may be processed in each step separately which is imperceptible to the player 6:03 Optimisation Tip: check collisions with tiles instead of collision objects, break a game up to a grid that stores whether a particular place is free or not and check that grid if you want to move 6:25 Demo: adding a view, instance deactivation is very expensive 7:08 A few functions to use for deactivation 7:40 Tip: you could put all the instances that can deactivate in one layer while your important ones in another layer 8:10 Tip: you could make a parent object 8:40 Those functions are expensive and do not need to be used every step 9:00 Changing the instance deactivation to be done every second instead 9:21 On vertex batches 10:06 What breaks them (Changing blend modes, drawing surfaces, submitting vertex buffers, using shaders, drawing primitives (draw rectangle, draw circle, etc. - better to draw a one pixel sprite, then stretch it), texture swaps) 10:40 Changing blend mode tip: avoid placing this function in every object, as that will break the vertex batch every time 11:11 Solution: make a parent then check it on the parent, and also remember to untick their visible check or leave a comment in their draw event 11:45 Texture swaps 12:11 What is a texture swap? 13:03 A way to put your stuff into one texture: manually assign your sprites to texture groups 13:22 Example: if a certain room is going to use a subset of sprites, then you can assign them to one texture 13:54 Micro-optimisations 14:03 Avoid: repeated function calls (e.g. keyboard_check(vk_right) can be just saved into a local variable [in the step event] then reused) 14:30 Avoid: repeat unnecessary function calls (e.g. a for loop - save the array_length into a local variable to get that value once) 15:16 Helpful uses of local variables 15:25 Addressing other instances: using dot operators can be costly 16:07 Example given: removing the need to use other.[something], and instead replacing it with a local variable. This means we no longer have to jump to the instance. The local variable is already local in scope and can be accessed anywhere within the event, whereas the max_health is an instance variable and would previously require that you do other.max_health. Local variable var mhealth = max_health would no longer necessitate the need for that. (my_health = other.max_health VS my_health = _m_health --> latter is more efficient) 17:36 Summary: use profiler, deactivate instances outside of view, reduce collisions, reduce batch breaks & texture swaps, don't repeat function calls, minimise jumps between instances by using local variables 18:00 There are more ways to optimise 18:08 Performance is not the ultimate thing, and sometimes readability and simplicity of code is far more important than removing a few nanoseconds off.
I would love to see this video on the start page for gms2. This info is invaluable for beginners, I especially liked the for loop optimization with regards to calling the array size check for each iteration. I have seen tons of example code out there with this same mistake, and it's extremely costly. Awesome work, your tutorials are so impressive, keep it up! =)
Cheers! I think it often pops up even in tutorials because it's a level of abstraction beginners may not understand. And even in stuff like create events, having the function in the loop isn't going to be a big deal because it's just going to effect 1 frame. Definitely can be costly if it's constantly running in a step event though! Thank you :)!
Very helpful video! Small tip: you can see how texture page will look like with current settings! Go to Options -> Windows -> Graphics -> Push "Preview" button.
Fine tips! After watching this video, I implemented in my game the function of disabling instances that do not appear on the screen and defined groups for each sprite in texture group and it really made the game faster! Thank you very much for your knowledge, my master! You helped improve the game Corpsenia
I really need to thank you for your message near the end. I often struggle with perfectionism, to the point that I try to fix problems that don't exist and get stuck in a loop of "this isn't good enough, do it again". I'm going to try my best to just make the game, while also keeping in mind these optimization tips when necessary.
Holy crap. Local variable scope had never even occured to me. Amazing what you learn when you watch random video's between coding sessions. FriendlyCosmonaut marry me !!!!
Thank you, this is a very good explanation, every explanation was enetrtaining and informative, I didn't feel the need to fast forward anything. I'm always a bit hesitant to run the profiler, but this makes it look far less intimidating. Thank you again.
I found a couple of amazing small tricks that helped my game to achieve better performance on PS Vita. For example, it was counter-intuitive to me that primitive objects are worse than sprites.Thank you very much! :)
I wish I had seen this video when I started GML a month ago. Luckily it's still early so I can still implement many of these tips into my current project. Thank you!
I feel pretty ashamed but... I've been programming in GMS for a lot of years and for all this time I didn't know the thing about local variables' scope. Better late than ever, I guess :D. I wonder if there will be other "Optimisation Tips" videos in the future, or at least I hope so..! Thanks for the lesson!
Haha don't worry at all, I remember it being a real eye-opener when I learned about it! There is actually quite a few more topics that could be covered on Optimisation, so a future vid is definitely on the table :)
I know this video is about optimisation, and I'll absolutely be looking over my code to improve it after I've got more of the game ironed out, but it makes my mind feel greater at ease to hear that messy code is normal and that you shouldn't focus on optimisation at first, especially as a beginner. I'm very new to properly coding things and I'm constantly worried that I'm doing stuff badly, it helps to know that it's normal, and it helps even more to get tips about how to clean it up after I'm done with it
I'm really glad to hear this - this is precisely right. When you're starting out, it's FAR more important for you to just learn, experiment, make progress in your projects, and have fun with your coding. The early stages are where most people quit, and it can be hard enough sustaining the motivation/determination for starting something new without being overwhelmed with the thought that you're "not doing it right". Just don't stop programming and learning, and you'll make progress :)
That deactivate instances line really fixed everything! I have spent multiple hours putting all tiles (which are objects) for all "sub rooms" in my main room... Ended up not running at all when I tried to load the game. I have a few seconds so everything can "Auto-Tile" where it lags out, but after that it runs perfectly!!!
Great video, I had no idea about the texture groups. The thousands of green dots could have been handled with particles which should have netted a considerable performance jump, especially at such a scale
Does Game Maker have any good support for running things in multiple threads? Or is basically everything run on a single thread? @16:50: "other"causes a "jump"? What is a jump in Game Maker? other.x should ideally only refer to a given memory location and you should be able to access and read that as fast as any other memory address. So this leads me to wonder how "objects" are handled in Game Maker and what overhead they add.
Are you sure your indexing is correct around the 14:54 mark? To me it seems you're off by 1 in the first case, and by two in the optimised case? Have you also actually profiled the getting of the array length has an effect? Seems like an optimisation that most compilers would make automatically (although I haven't ever used GM)
you haven't used gamemaker but you're questioning her obvious mastering of the language after watching 15 minutes of a video for an application you don't even use? sounds fishy mate
Hi. Great video, lots of useful tips I didnt know about. I have a question: i am working on a survival game and I am wondering, is it more efficient to have a completely separate object for each type of animal/resource or to have a single object with a different state for each animal/resource (using a switch statement)? Thanks
I didn't know that about the scope of local variables, so when I needed to use a local variable inside of a with I actually converted that local variable into a regular variable just to use the "other" keyword lol.
I agree so much with your say on optimization it has been the most develop breaking thing in me trying to make this sandbox game of mines.Still im trying to find a way to chunk ds_grids.
I find it kinda amusing that the microoptimization to break the array_length call out of the for loop still has the -1 in there, so you're still gonna do that math operation every iteration of the loop :P (Compile-time constant expressions are simplified to a single constant but since this is runtime it probably won't get saved by the compiler) Goes to show how there's always room to improve things further, "perfect is the enemy of good" and so on, I guess.
What if instead of creating var's in the Step or Draw events, just create them as instance variables in Create event. Then only chage them in Step or Draw events. Example: Look at 7:33 What I mean is: // In Create event cam = view_camera[0]; cleft = camera_get_view_x(cam); ctop = camera_get_view_y(cam); cw = camera_view_get_width(cam); ch = camera_view_get_height(cam); // In Step event // All other code
If you write in Step event: var my_variable = x * 2 + y * 2; It will be created, assigned and deleted every Step. But if you do like this: // In Create event my_variable = 0; //In Step event my_variable = x * 2 + y * 2; It will be created just once in Create event. In Step event variable will be only changed and it will be deleted only once in Clean-Up event. Correct me if I'm wrong.
You could do this. Certainly as I note in the videos, the get_width and get_height function calls/variables should be moved to the create event and declared just once. But the "cleft" and "ctop" variables are the camera's position, and unlike the camera's width and height, its x and y position ARE going to be changing as the game progresses. So we need to update those every step (so, keep them in the step event). As for your second point - you're correct. Temporary variables are created at the start of the script, and destroyed once that script finishes running. The instance variable will stick around until the object is destroyed. In this case it doesn't really matter what way you go about it - the memory is managed fine either way. But if you needed the camera's co-ordinates elsewhere (say, in both the step event and draw event) then it will be more useful to have it as an instance variable. Hope that makes sense. Great questions!
So glad I found your channel! I find these videos very helpful. I have a question about data structures (ds_maps/ds_lists): I've looked them up and it's very important to always destroy them when you don't need them anymore so that your game can free up memory. If I assign my data structures to a local variable, do I still need to destroy them when I'm done with them?
Thank you! Yes, I'm afraid that doesn't destroy it. What you're actually saving when you assign a data structure to a variable (local, instance, global, whatever) isn't the "data structure" itself, it's the ID. So the only thing that will happen when the local variable you assign the data structure to gets destroyed, is you'll lose your way of referencing it.
important tip: Use "Cleanup" event instead of "Destroy" event, because "Destroy" event is called ONLY if you destroy an object by instance_destroy() function! So, "Destroy" event will NOT be called if you loading the next room, for example!
Hello, thanks for this informative video! Did you source most of this information from the manual? Or more specifically how did you identify all these issues and their fixes?
Cheers! A lot of the info about performance sinks (deactivating objects, reducing texture swaps/batch breaks, collisions) has been well known and discussed for years in the GM community (though a lot of these issues/fixes can be applicable across game engines). I've internalised and read a lot of forum posts and blog posts, eg. here www.yoyogames.com/search/results?utf8=%E2%9C%93&query=optimisation, though note some of them may be a little out of date. The GameMaker Discord and reddit can also be really great places to find discussion on performance/optimisation, with a lot of users contributing "tests" (such as for comparing the speed of different functions or data structures). The solutions such as deactivating instances, reducing texture batches/swaps, minimising the use of expensive functions if necessary, as well as a lot of the tips for coding "best practises" are also quite widespread. It would be difficult to attribute them to any one person as I see a lot of them popping up everywhere!
it's very funny but yesterday I was wondering exactly what type of optimization could be made in GMS2 (mainly in scripts). I think that for beginners the stranger thing to wrap our head around is the fact that there is a bunch of code running every single frame, I sort of understand now why in games like League Of Legends there are a lot of calculations done every 0.5 seconds instead of every frame.
Friend linked me this video. Great job but I have one issue. Instance deactivation isn't worth it really. For simple objects (i.e trees in RPG) it's better to just disable visibility outside view. Activation and deactivation just takes too much processing time, even when run every few seconds. Other than optimization issue it might create lots of bugs with addressing not activated instance. Deactivation is better than setting visible=false only for objects that run heavier code, but then most of the time you want them to run it still. There is not really many examples when activation could be used efficiently.
@@thomasrosebrough9062 Well yes, because instance deactivation also limits draw calls by eliminating objects in the game. But the process of deactivation and activation takes more computing power than necessary. And if we want to flex at numbers I was running 100k spaceships in a dog fight "of screen" on Intel Atom 1.06Ghz in 59-60 FPS
for me i suspect my problem is im using still high quality images and animations from pre rendered 3d stuff and i can not figure out how to lower the images file sizes without loosing quality
(sorry for my english I am french) : I tried to make a game with a home-made 3D graphic motor (with projections and triangles) but when a place more than 1 tiny room, my game drop to 5fps :/ I can't display more than 1000 of triangles without a drop of fps :( But your video help a little, thank you
Hey, I don't know if you have an answer for me on this or not but how do I avoid stagnation? It's depressing honestly, I've tried over and over to make a game, I don't lack in skill when it comes to creating any of the required media but I often start a project, get it to a certain point and then give up on it. It drives me nuts, I've even abandoned creating games altogether more than once but it always just leaves me feeling empty. Creation is in my blood, I have to make things or my life just falls to shit. Strangely enough, even knowing this, I still can't finish one damned thing. It's as if someone gave me all of the tools and information that I need and instead of using them to focus on one thing I just find myself frustratingly distracted and immobile. I've tried giving it time, I've tried forcing myself, I'm at a loss, I just seem to be stuck and I don't know how to get out.
Do you find it more efficient to have a "drawing controller" that handles all your games' draw events or is it just easier to organize & decide whats get drawn when. Or both even?
It depends (a LOT). I would say if your draw events are relatively simplistic it would be better to have them in the separate objects. However if you're applying lots of effects/shaders/playing with surfaces/have built your own way of rendering everything, it could be better to have it from a controller. It's often a matter of scale, too - if you graph two methods along an increasing scale of objects, you may find one is more efficient with fewer objects, and then at >100 objects the other method is more efficient. I wouldn't worry too much, and opt for what makes more sense to organise/program. (Unless you have performance issues or are planning on building a MMORPG!)
Adobe Premiere Pro, but to be honest I don't know if I can recommend using it because there's a lot that frustrates me about the program. It also probably doesn't help that I just hate the process of editing lol :)
In short: You are doing something wrong if you are manually writing code for every object instead of making a group for them or if you are using a mechanic that would require collision check on anything what collides with the same thing. Also another tip. Make use of surfaces well guys.
Shoutout to Ariak for his feedback as I was making the video! Thank you :)!
Thank you for all of the help you've provided me along my GMS journey. This video especially has improved my workflow and game as a whole. I'd love a sequel to this video if there are any more tips you could share.
The quality of your videos is incredible.
holy cats, I did not realize a function call in a for loop would check every single time. You just gave my game a pretty significant, easy performance boost!
Ofc it does :)... There would be no way for the interpreter to know if the return value of your function would be the same every time so the function call has to take place. If you have a function call in the assignement part
for(var i = getMyValue()
then it will only get called once though since the assignment only happens once.
By far the best Game Maker video I've ever seen. Great content and presentation. Narrated very well, great subtle video effects and snappy editing, coloring and presentation of the code is great, analogies are clever, just absolutely fantastic.
1:25 Common performance sinks: drawing sprites, collisions, amount of objects
1:53 Run the profiler if you are having performance issues
2:16 We want the fps shown to be as high as possible when in debug mode
2:41 What we can see in the profiler
3:31 Demo: increasing the number of instances in the room
4:35 Demo: adding collision checks
5:00 Optimisation Tip: instead of the bullet checking for collision with player, check a player's collision with a bullet instead. (100 checks vs 1)
5:37 Collision functions' limitations (like place_meeting and instance_place)
5:54 The limitations generally shouldn't be a problem if 3 bullets are seemingly hitting at the same time, since they may be processed in each step separately which is imperceptible to the player
6:03 Optimisation Tip: check collisions with tiles instead of collision objects, break a game up to a grid that stores whether a particular place is free or not and check that grid if you want to move
6:25 Demo: adding a view, instance deactivation is very expensive
7:08 A few functions to use for deactivation
7:40 Tip: you could put all the instances that can deactivate in one layer while your important ones in another layer
8:10 Tip: you could make a parent object
8:40 Those functions are expensive and do not need to be used every step
9:00 Changing the instance deactivation to be done every second instead
9:21 On vertex batches
10:06 What breaks them (Changing blend modes, drawing surfaces, submitting vertex buffers, using shaders, drawing primitives (draw rectangle, draw circle, etc. - better to draw a one pixel sprite, then stretch it), texture swaps)
10:40 Changing blend mode tip: avoid placing this function in every object, as that will break the vertex batch every time
11:11 Solution: make a parent then check it on the parent, and also remember to untick their visible check or leave a comment in their draw event
11:45 Texture swaps
12:11 What is a texture swap?
13:03 A way to put your stuff into one texture: manually assign your sprites to texture groups
13:22 Example: if a certain room is going to use a subset of sprites, then you can assign them to one texture
13:54 Micro-optimisations
14:03 Avoid: repeated function calls (e.g. keyboard_check(vk_right) can be just saved into a local variable [in the step event] then reused)
14:30 Avoid: repeat unnecessary function calls (e.g. a for loop - save the array_length into a local variable to get that value once)
15:16 Helpful uses of local variables
15:25 Addressing other instances: using dot operators can be costly
16:07 Example given: removing the need to use other.[something], and instead replacing it with a local variable. This means we no longer have to jump to the instance. The local variable is already local in scope and can be accessed anywhere within the event, whereas the max_health is an instance variable and would previously require that you do other.max_health. Local variable var mhealth = max_health would no longer necessitate the need for that. (my_health = other.max_health VS my_health = _m_health --> latter is more efficient)
17:36 Summary: use profiler, deactivate instances outside of view, reduce collisions, reduce batch breaks & texture swaps, don't repeat function calls, minimise jumps between instances by using local variables
18:00 There are more ways to optimise
18:08 Performance is not the ultimate thing, and sometimes readability and simplicity of code is far more important than removing a few nanoseconds off.
I would love to see this video on the start page for gms2. This info is invaluable for beginners, I especially liked the for loop optimization with regards to calling the array size check for each iteration. I have seen tons of example code out there with this same mistake, and it's extremely costly. Awesome work, your tutorials are so impressive, keep it up! =)
Cheers! I think it often pops up even in tutorials because it's a level of abstraction beginners may not understand. And even in stuff like create events, having the function in the loop isn't going to be a big deal because it's just going to effect 1 frame. Definitely can be costly if it's constantly running in a step event though!
Thank you :)!
people have to have a journey.. not everything can be placed in front of everyone's face. you found this tutorial.. be happy. spread the word. :)
Super helpful 6 years later! Thank you!
Very helpful video!
Small tip: you can see how texture page will look like with current settings! Go to Options -> Windows -> Graphics -> Push "Preview" button.
Yes, thank you!
Fine tips! After watching this video, I implemented in my game the function of disabling instances that do not appear on the screen and defined groups for each sprite in texture group and it really made the game faster! Thank you very much for your knowledge, my master! You helped improve the game Corpsenia
Your videos are so straightforward and helpful, I hope you decide to make videos again in the future.
I really need to thank you for your message near the end. I often struggle with perfectionism, to the point that I try to fix problems that don't exist and get stuck in a loop of "this isn't good enough, do it again". I'm going to try my best to just make the game, while also keeping in mind these optimization tips when necessary.
Holy crap. Local variable scope had never even occured to me. Amazing what you learn when you watch random video's between coding sessions. FriendlyCosmonaut marry me !!!!
Thank you, One of my games that has had awful performance in HTML for months, works perfectly thanks to your optimization tips.
Thank you, this is a very good explanation, every explanation was enetrtaining and informative, I didn't feel the need to fast forward anything. I'm always a bit hesitant to run the profiler, but this makes it look far less intimidating. Thank you again.
very precise solutions for advanced problems. Thanks for the amazing tips!
If I could give you 10 thumbs up I would have. You're a natural. Thank you.
I found this tutorial accidentally... One of the best tutorials I have ever saw, not only for GM!
Thank you! Just starting out learning game dev, this video has been a great help to me. Hopefully you keep posting content and deving!
Great video! I am thankful for people like you that make it possible for many to better themselves as game developers
I found a couple of amazing small tricks that helped my game to achieve better performance on PS Vita. For example, it was counter-intuitive to me that primitive objects are worse than sprites.Thank you very much! :)
I wish I had seen this video when I started GML a month ago. Luckily it's still early so I can still implement many of these tips into my current project. Thank you!
I love your videos, they're so incredibly clear, well-made, and easy to understand. Thank you.
Very well done, I came across this video while looking up videos on Source Control with GMS2. Glad I found it, keep up the great work!
At 15:18 there is a tiny little mistake: alength already is the array length minus one but in the loop you subtract another time.
Fantastic tutorial, good work.
I just wanted to thank for all your tutorials. They're incredibly usefull and well structured.
I feel pretty ashamed but... I've been programming in GMS for a lot of years and for all this time I didn't know the thing about local variables' scope. Better late than ever, I guess :D.
I wonder if there will be other "Optimisation Tips" videos in the future, or at least I hope so..!
Thanks for the lesson!
Haha don't worry at all, I remember it being a real eye-opener when I learned about it! There is actually quite a few more topics that could be covered on Optimisation, so a future vid is definitely on the table :)
This is a fantastic video. Thank you.
Wow, exceptional video.
Thank you, this is one of the most helpful GMS2 tutorial video I've seen in a long time.
I know this video is about optimisation, and I'll absolutely be looking over my code to improve it after I've got more of the game ironed out, but it makes my mind feel greater at ease to hear that messy code is normal and that you shouldn't focus on optimisation at first, especially as a beginner. I'm very new to properly coding things and I'm constantly worried that I'm doing stuff badly, it helps to know that it's normal, and it helps even more to get tips about how to clean it up after I'm done with it
I'm really glad to hear this - this is precisely right. When you're starting out, it's FAR more important for you to just learn, experiment, make progress in your projects, and have fun with your coding. The early stages are where most people quit, and it can be hard enough sustaining the motivation/determination for starting something new without being overwhelmed with the thought that you're "not doing it right". Just don't stop programming and learning, and you'll make progress :)
That deactivate instances line really fixed everything! I have spent multiple hours putting all tiles (which are objects) for all "sub rooms" in my main room... Ended up not running at all when I tried to load the game. I have a few seconds so everything can "Auto-Tile" where it lags out, but after that it runs perfectly!!!
holy shit this video is amazing. i had no idea that local variables dont need the other. in order to call them. thank you so much
Delightful in depth video! Well done, and thank you.
Thanks love all your videos, they are a big help and you go into a good level of detail in them.
These videos are so well made, and surely take a lot of time; I just had to leave a comment. Great job, really. Liked and subbed.
This is amaznig! Thank you so much for this information and tips!
Thanks a ton for this video. I'm new to Game maker and this is invaluable information!
Useful and to the point. Cheers.
I've often wondered how that debug overlay was turned on. Good tips.
This was a great help, thanks !
Great video, I had no idea about the texture groups. The thousands of green dots could have been handled with particles which should have netted a considerable performance jump, especially at such a scale
as always this is worth gold :). thanks a lot and keep up the awesome work
Amazing video, it helped me a lot!!
Your videos are so incredibly helpful, thank you so much for all of this
You are best ! (Hello from Russia)
thank you! as a newbie, this is great!
Haha! We use those asteroid assets in my programming class.
Thanks for the video. :)
Nice video thanks, I learned a lot.
Love your videos! I might need to binge-watch these vids this weekend :)
I would love to see more stuff on optimization, if there are still more major/general tips to give.
Does Game Maker have any good support for running things in multiple threads? Or is basically everything run on a single thread?
@16:50: "other"causes a "jump"? What is a jump in Game Maker? other.x should ideally only refer to a given memory location and you should be able to access and read that as fast as any other memory address. So this leads me to wonder how "objects" are handled in Game Maker and what overhead they add.
Oh my god this is incredible, THANKS!
Your tutorials are super helpful!
Very well explained! Thank you so much for make this video. :)
This is great, thank you! Thumbs up.
Thank you for the video, It was very helpful.
Are you sure your indexing is correct around the 14:54 mark? To me it seems you're off by 1 in the first case, and by two in the optimised case? Have you also actually profiled the getting of the array length has an effect? Seems like an optimisation that most compilers would make automatically (although I haven't ever used GM)
you haven't used gamemaker but you're questioning her obvious mastering of the language after watching 15 minutes of a video for an application you don't even use? sounds fishy mate
helpful,clear tutorial.thanks a lot!!!!!
Great, as always ♥
Thank you so much!
Hi. Great video, lots of useful tips I didnt know about. I have a question: i am working on a survival game and I am wondering, is it more efficient to have a completely separate object for each type of animal/resource or to have a single object with a different state for each animal/resource (using a switch statement)?
Thanks
Very good video and channel, thanks
I didn't know that about the scope of local variables, so when I needed to use a local variable inside of a with I actually converted that local variable into a regular variable just to use the "other" keyword lol.
I agree so much with your say on optimization it has been the most develop breaking thing in me trying to make this sandbox game of mines.Still im trying to find a way to chunk ds_grids.
Very useful video thank you
I find it kinda amusing that the microoptimization to break the array_length call out of the for loop still has the -1 in there, so you're still gonna do that math operation every iteration of the loop :P (Compile-time constant expressions are simplified to a single constant but since this is runtime it probably won't get saved by the compiler)
Goes to show how there's always room to improve things further, "perfect is the enemy of good" and so on, I guess.
I wish you were my math teacher 😊
What if instead of creating var's in the Step or Draw events, just create them as instance variables in Create event. Then only chage them in Step or Draw events. Example:
Look at 7:33
What I mean is:
// In Create event
cam = view_camera[0];
cleft = camera_get_view_x(cam);
ctop = camera_get_view_y(cam);
cw = camera_view_get_width(cam);
ch = camera_view_get_height(cam);
// In Step event
// All other code
If you write in Step event:
var my_variable = x * 2 + y * 2;
It will be created, assigned and deleted every Step. But if you do like this:
// In Create event
my_variable = 0;
//In Step event
my_variable = x * 2 + y * 2;
It will be created just once in Create event. In Step event variable will be only changed and it will be deleted only once in Clean-Up event.
Correct me if I'm wrong.
You could do this. Certainly as I note in the videos, the get_width and get_height function calls/variables should be moved to the create event and declared just once. But the "cleft" and "ctop" variables are the camera's position, and unlike the camera's width and height, its x and y position ARE going to be changing as the game progresses. So we need to update those every step (so, keep them in the step event).
As for your second point - you're correct. Temporary variables are created at the start of the script, and destroyed once that script finishes running. The instance variable will stick around until the object is destroyed. In this case it doesn't really matter what way you go about it - the memory is managed fine either way. But if you needed the camera's co-ordinates elsewhere (say, in both the step event and draw event) then it will be more useful to have it as an instance variable.
Hope that makes sense. Great questions!
Thanks!
So glad I found your channel! I find these videos very helpful. I have a question about data structures (ds_maps/ds_lists): I've looked them up and it's very important to always destroy them when you don't need them anymore so that your game can free up memory. If I assign my data structures to a local variable, do I still need to destroy them when I'm done with them?
Thank you! Yes, I'm afraid that doesn't destroy it. What you're actually saving when you assign a data structure to a variable (local, instance, global, whatever) isn't the "data structure" itself, it's the ID. So the only thing that will happen when the local variable you assign the data structure to gets destroyed, is you'll lose your way of referencing it.
Ah makes sense! Thank you :) Edit: So that's why in the debugger a data structure is first shown as an ID instead of the actual list
important tip:
Use "Cleanup" event instead of "Destroy" event, because "Destroy" event is called ONLY if you destroy an object by instance_destroy() function!
So, "Destroy" event will NOT be called if you loading the next room, for example!
Thank you
Hello, thanks for this informative video! Did you source most of this information from the manual? Or more specifically how did you identify all these issues and their fixes?
Cheers! A lot of the info about performance sinks (deactivating objects, reducing texture swaps/batch breaks, collisions) has been well known and discussed for years in the GM community (though a lot of these issues/fixes can be applicable across game engines). I've internalised and read a lot of forum posts and blog posts, eg. here www.yoyogames.com/search/results?utf8=%E2%9C%93&query=optimisation, though note some of them may be a little out of date. The GameMaker Discord and reddit can also be really great places to find discussion on performance/optimisation, with a lot of users contributing "tests" (such as for comparing the speed of different functions or data structures).
The solutions such as deactivating instances, reducing texture batches/swaps, minimising the use of expensive functions if necessary, as well as a lot of the tips for coding "best practises" are also quite widespread. It would be difficult to attribute them to any one person as I see a lot of them popping up everywhere!
great video
top video!!!
it's very funny but yesterday I was wondering exactly what type of optimization could be made in GMS2 (mainly in scripts). I think that for beginners the stranger thing to wrap our head around is the fact that there is a bunch of code running every single frame, I sort of understand now why in games like League Of Legends there are a lot of calculations done every 0.5 seconds instead of every frame.
Awesome point! Thanks for sharing :)
Friend linked me this video. Great job but I have one issue. Instance deactivation isn't worth it really. For simple objects (i.e trees in RPG) it's better to just disable visibility outside view. Activation and deactivation just takes too much processing time, even when run every few seconds. Other than optimization issue it might create lots of bugs with addressing not activated instance.
Deactivation is better than setting visible=false only for objects that run heavier code, but then most of the time you want them to run it still. There is not really many examples when activation could be used efficiently.
Personally I made a game with a room size of 26000 by 26000 and thousands of objects. Deactivating was hugely helpful in making it run effeciently.
@@thomasrosebrough9062 Well yes, because instance deactivation also limits draw calls by eliminating objects in the game. But the process of deactivation and activation takes more computing power than necessary.
And if we want to flex at numbers I was running 100k spaceships in a dog fight "of screen" on Intel Atom 1.06Ghz in 59-60 FPS
for me i suspect my problem is im using still high quality images and animations from pre rendered 3d stuff and i can not figure out how to lower the images file sizes without loosing quality
nice tutorials
(sorry for my english I am french) : I tried to make a game with a home-made 3D graphic motor (with projections and triangles) but when a place more than 1 tiny room, my game drop to 5fps :/
I can't display more than 1000 of triangles without a drop of fps :(
But your video help a little, thank you
Hey, I don't know if you have an answer for me on this or not but how do I avoid stagnation? It's depressing honestly, I've tried over and over to make a game, I don't lack in skill when it comes to creating any of the required media but I often start a project, get it to a certain point and then give up on it. It drives me nuts, I've even abandoned creating games altogether more than once but it always just leaves me feeling empty. Creation is in my blood, I have to make things or my life just falls to shit. Strangely enough, even knowing this, I still can't finish one damned thing. It's as if someone gave me all of the tools and information that I need and instead of using them to focus on one thing I just find myself frustratingly distracted and immobile. I've tried giving it time, I've tried forcing myself, I'm at a loss, I just seem to be stuck and I don't know how to get out.
Do you find it more efficient to have a "drawing controller" that handles all your games' draw events or is it just easier to organize & decide whats get drawn when. Or both even?
It depends (a LOT). I would say if your draw events are relatively simplistic it would be better to have them in the separate objects. However if you're applying lots of effects/shaders/playing with surfaces/have built your own way of rendering everything, it could be better to have it from a controller. It's often a matter of scale, too - if you graph two methods along an increasing scale of objects, you may find one is more efficient with fewer objects, and then at >100 objects the other method is more efficient.
I wouldn't worry too much, and opt for what makes more sense to organise/program. (Unless you have performance issues or are planning on building a MMORPG!)
do global variables count as switching between instances, or is there a reason we don't use so many global variables?
Helpful!
i just started one week ago my first simple game and i finished the gameplay today i just need the design but im not good at pixelart or design :P
when i develop for android, i see real fps 700 but in game it get framed i dont know why, my light renderer maybe
What editing software do you use?
Adobe Premiere Pro, but to be honest I don't know if I can recommend using it because there's a lot that frustrates me about the program. It also probably doesn't help that I just hate the process of editing lol :)
To myself:
Go to 17:38 to see the summary
There is also instance_place_list I think lul
this video is 6 years old rn this person could have gotten married and have children or dead , the possibilities are endless
In short:
You are doing something wrong if you are manually writing code for every object instead of making a group for them or if you are using a mechanic that would require collision check on anything what collides with the same thing.
Also another tip.
Make use of surfaces well guys.