 When you create a new Godot project, do you know at how many frames per second your project is running? It's not apparently obvious when you set it up so you might not even realize that your project by default runs with Uncapped frames per second, which may be using up a lot of your players resources Maybe you want that maybe you don't in this video We're gonna look at the code for how to change the max frames per second how to get the frames per second that are Your games currently running at and give you some options so that you'll learn more. What we've got is a simple scene 2d that says FPS exploring with a label and a label that just says current FPS question mark question mark So let's get our current frames per second. We'll attach a script to main I Miss that up. There we go. And we'll just go ahead and in every run of the process function We'll go ahead and we'll set our current FPS dot text to a string. That's current FPS space and then we'll plus and we'll pass a string in of the Engine dot Get frames per second. That's a function you can call on the global engine and that will return how many frames per second we're getting so the game's running and We're hovering at about 90. That's dependent on how fast your computer is and What your game's doing and all that sort of thing. Let me make that a little bit bigger just because it is a little bit tiny and We'll just go ahead and set it to a header medium So that's all you need to do to get the current FPS is engine dot get frames per second Maybe you have a setting that lets you turn on in your game show how many frames per second your game is running at That's pretty nice and then You can limit it by in your ready function You can say engine dot Max FPS is equal to whatever value you want it to so we'll set it to 60 And now this would only happen in our main scene I don't know if it would apply from scene to scene But what I would generally do is Yeah, I would I would test that out check But I would generally create an autoload Constant singleton called global that on global ready. It's at your engine max FPS But now you can see we're hovering at around 60 frames per second instead of about 90 so we've limited it and you can go and change that to 30 if You for some reason wanted it to be 30 and that's all well and good, right? We're getting it with get frames per second. We're setting it with max FPS now. Let's just add a little drop down Let's give our player an option. So and let's also before we do that let's Add a label called max FPS Just so we can easily visualize what we've got and then in our script. We'll just say Max FPS subtext is equal to max FPS String and you can get that value. It's a property. So you can just do that make sure that works Great. So it's at the 30. It's hovering at about 30. That's perfect. It'll never be precise. Sometimes it might drop a frame or two Now let's go ahead and wire up a drop down So in Godot you can add a node called option button and it shows a drop down of options in The inspector over here, you'll see Selected as negative one and then there's a drop down. You can expand for items. So we'll say unlimited We'll give it an ID of zero. We'll say 60 and then we'll say 30 and These IDs matter here. We'll reference them in the code and we'll set selected to be zero So that it's by default Selects unlimited because that's the default and then we'll add a label to decorate it. That just says You know set max FPS We'll drag that Down Here there we go couple things We'll go into our script and We'll set the max FPS to zero which is unlimited We'll Rename some of our nodes and then we need to hook up a signal that says item selected So on FPS drop down item selected. We'll connect it to a new function here that We'll use to set our engines max FPS. So we'll say up here. We'll say We need to do a couple of things. We'll say We'll create a constant called frame Dick And we'll set the zero index to be zero because that's unlimited We'll set the one index which is 60 to 60. We'll set two to be 30 It's sort of it's sort of a weird thing. We'll make it FPS dictionary and So this limb lets us do a really nice Thing in our code where we can then say engine dot max FPS is equal to FPS dictionary Which is a constant it doesn't change and then we just pass in the index of The selected item here and it will set our engines max FPS and then what we need to do too is we need to then say Max FPS text is set to the new one So we'll just make a function called set max FPS text Funk set max FPS text So then we set that there after we set it here We go ahead and do that We can remove that value here and I think We'll now be able to easily change our max FPS So max FPS zero is unlimited right and so it's running at about 90 if we change this to 60 You'll see our current FPS drops and now every frame. We're getting about 60 and then 30 Drops it down to 30 and you'll see if we let it go unlimited. It'll jump back up So that's a really easy way quick way to create a drop-down option You I to change your max FPS and this might be Something that you add in your game settings that gives your players options, right? Maybe they have an older computer and they want to have it run smoothly at 30 instead of jumping up and down Around 60 or maybe you really you know You want to give them the option to have unlimited because they have a really fast computer And they want to have the render time has have run faster So that is How you work with FPS to recap you set engine dot max FPS Do a value? Whatever you want it to be 30 60 or 0 for unlimited or common values You get it with engine dot get frames per second, which is a function and then here. We just did some advanced Work where we defined a dictionary that maps to the option Values here. I'll open this here so we can correlate them so unlimited as our text And we have ID of zero 60 is our text here and this idea of one right that matches and we need to have this dictionary the key of our Index in the drop-down maps to the number and frames per second because yeah We need some way to correlate those values. You could use the dictionary here and expand it a bit to set the option Button items dynamically that might be preferable, but I thought that showing this in the UI would be quite nice, so that is Frames per second in Godot 4 explained. Thanks for watching. Take care. See you