UE5 GameMode vs GameInstance Explained

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey i'm max and today i'll show you the difference between game mode and game instance in unreal engine 5. so let's get right into it first of all the game mode is per level so if i go into edit project settings and then i search for game mode i can see default game mode here is my tutorial game mode if i want to change it i can right click go into blueprint class and then click game mode base then i can give it a name like bp game mode now if i go back into my project settings and search for game mode i can click on it and i can change it for my bp game mode i just made if i open this bp game mode i can go into event graph and of the begin play i can drag and do for example a print string so if i type in it default game mode started i compile and then i run any map i will see default game mode started however if i want i can for example duplicate it and in this other one i can print a different message like second game mode started so you could have for example one game mode that's team deathmatch or another one that's captured the flag and each one of them would set up the game in a different way but if i click play you can see it still says default game mode because i didn't change it so now i'm on my map 3 if i go into window i can click on world settings here to see the window appear to the right then i can go on game mode override and click my new game mode so now if i load map3 i get second gamemode started but if i load my map 2 i still get default gamemode started so you can see how you can use this to have different behaviors on different maps or different game modes i think it's also important to note that if you have the same game mode on two different maps and then you change map the values are not going to be saved so here in my default game mode i did a little setup to show that it prints default gamemode started then it prints the value of the variable which is default 0 then it sets it to 20 and print it again if i start my game you can see it prints default gamemode started 0 and then 20 because i changed it to 20. but if i touch this cube here it's going to load another map and you can see it prints again default started 0 and 20. so you can see it goes back to zero when you change map and that's the main difference between game mode and game instance because you can see if i create a game instance and do the same thing so i just do blueprint class and i search for game instance and i create a game instance right here i can just call it blueprint game instance when i open it up you can see there's absolutely nothing in here because it's not an actual actor you can see the game mode here as an actor you could add different things to it different components but the game instance is just data it's just an object game instead actually don't have begin play events because they're not an actor instead you have to use the event init which is going to happen at the start when the game instance is being initialized and then if i print the same thing i did in gamemode with the variable you can see when i run my game nothing happens because i didn't set the game instance so you have to go in edit project settings and then search for game instance you can see here it doesn't say default game instance because there's just one you can only have one game instance in your whole game and that's the point of a game instance it doesn't change when you change level when you change game mode no matter what you do you have one and the value stays the same all the time so here if i select my bp game instance you can see when i run my game it says default game instead started 0 20. you can see it also happens before the game mode and if i touch my cube here to change map the game mode restarted but the game instance didn't call it again because it didn't get restarted it's still the same game instance and if i add in my game instance a function let's say print var and in my print var function i simply print fire variable in the game instance then i can go in my game mode and do get game instance just like this and then cast it to my bp game instance just like this now i can drag from this and call my print bar function i just added another print here to make it easier to read so if i start my game now you can see game instance started 0 20 game mode started 0 20 game instance var value 20 because we just changed it here now if i open another map you can see it will print again game mode started but not again game instant started and the game instance var value is again 20. let's remove the game mode prints to make it easier to see again so you can see default game instead started it was at zero now i set it to 20 so the game instance bar value is 20. now if i load another map you can see game instance var value is again 20 but the game mode value is back to zero so basically game mode is per map but game instance there's only one for your whole game for every mode you play for every type of mini games you can play it's the same game instance and it doesn't reload when you change the map the value stays the same so game instances are usually used to save things and load things such as the player's stats so let's say you're doing an rpg in your game mode you might put the enemies that were spawned but in the game instance you might put the player's inventory because if you change to the main menu you want to keep the inventory to be able to look it up for example and you don't want the player to lose its inventory if it enters a dungeon or another map so basically game mode is one per map and game instance is one per game it's that simple hopefully you enjoyed this video and you understood well if you did make sure to leave a like and subscribe
Info
Channel: MaxMakesGames
Views: 13,827
Rating: undefined out of 5
Keywords: gamdev, game dev, game making, game, programming, code, games, coding, 3D, development, dev, indie, solo
Id: 0pAhqA2Sgto
Channel Id: undefined
Length: 5min 29sec (329 seconds)
Published: Sat Jun 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.