HTF do I? Use the GameInstance Object in Unreal Engine 4

  Рет қаралды 56,286

Mathew Wadstein Tutorials

Mathew Wadstein Tutorials

Күн бұрын

Пікірлер: 82
@xylvnking
@xylvnking 5 ай бұрын
another night i find myself up at 2am watching your tutorials. thanks man
@Foreverstudio0192
@Foreverstudio0192 4 жыл бұрын
Wow this was a very thorough, easy to understand tutorial. You are really good at explaining things!
@brunomilcos
@brunomilcos 7 жыл бұрын
I love your tutorials, always very clear and to the point! Thanks!
@tailwhipolaf
@tailwhipolaf 4 жыл бұрын
I was going to same the same thing lol
@metafuel
@metafuel 4 жыл бұрын
You rock Mathew. I hope you and your loved ones are safe. Thank you for sharing your knowledge in such a brilliant and concise manner. Much love in crazy worldwide quarantine times.
@FitGameDeveloper
@FitGameDeveloper 5 жыл бұрын
Thanks! Your tutorials are always the most-helpful on any topic they cover. Having the debug buttons to test the variable getting/setting was critical for my problem troubleshooting.
@terraint3697
@terraint3697 6 жыл бұрын
Thank you as always for the straight to the point information about what I am looking to learn! Amazing!
@iangriffiths2483
@iangriffiths2483 5 жыл бұрын
Cheers for this video Mathew, been hitting my head against the wall all day looking to transfer data between two game modes.
@mryonmusic253
@mryonmusic253 5 жыл бұрын
Dude. Thank you. You saved me from insanity. Not sure how I missed the GameInstance setting.
@chaotickreg7024
@chaotickreg7024 3 жыл бұрын
This is an important video. I think the easiest way to think about the Game Instance is it's your "Save File." If the game needs to check your wallet or game progress then it will check your game instance in much the same way it would check a save file. Save games should probably be saved as a separate file but that ruins my metaphor.
@samarmstrong7374
@samarmstrong7374 Жыл бұрын
Thanks Mathew, you are an excellent teacher
@NinjaThug
@NinjaThug 3 жыл бұрын
Awesome info, as always!
@myunglee8163
@myunglee8163 7 жыл бұрын
Your tutorial is awesome. Really. Thanks a lot and please keep on going!!
@MattJSowards
@MattJSowards 4 жыл бұрын
is there a way to rename an existing game instance, i want to parent one but they're both identically named the same. any solution i renamed it by right click rename with no errors but it still shows original game instance name when going to add it and same issue/
@TorQueMoD
@TorQueMoD 4 жыл бұрын
If you hover over the two GameInstances, the only one that's actually the root GameInstance from the engine, will have a long description as a tooltip. Any custom game instances will only show the name of that GameInstance as its tooltip. This is how you can tell them apart if they're named generically. You always want to parent from the root GameInstance when you make your own.
@DevinDTV
@DevinDTV 7 жыл бұрын
Two possibly related questions: Why store things in the player blueprint at all instead of just directly in the game instance? What if you have multiple players loading new levels, how do you store their stats individually? I love your videos btw.
@benjiusofficial
@benjiusofficial 2 жыл бұрын
It's the same idea as public and private functions. If the information is shared between objects (and is persistent), store in the instance. If they are only referenced by the player (and are transient), store it on the player blueprint.
@vaughanmacegan4012
@vaughanmacegan4012 2 жыл бұрын
I am a noob in that I have done some small courses but still don't understand a lot of things. Now in this tutorial you have a bluse line running off the Generic Cast to a spot called "target". I don't have anything like that in my Set box. What am I doing wrong?
@ErikRoberts1981
@ErikRoberts1981 Жыл бұрын
Hi Mathew, this seems to be more or less what I'm looking for. However, instead of setting health, I'm trying to set the "play to" score where the player can set the desired score that they want to play up to. Is there a better way to do this instead of how you've done it above?
@MartKart8
@MartKart8 2 жыл бұрын
All I'm finding is videos on health when it comes to game instance and nothing else, would of been good if it was a collectable? Sure the health could be good for going to a next level, but when I turn the game off I might want my health to be back at the top and collectables I have kept on me?
@LDT7Y
@LDT7Y Жыл бұрын
How big should the game instance file ideally be at maximum (for a data heavy rpg, specifically)? I'm a bit concerned (perhaps unneccessarily) that my game instance is already about 20mb and I haven't even added most of the 400+ quests to it yet.
@RyanSturtevant
@RyanSturtevant 8 жыл бұрын
Thanks for all of your great videos! I wanted to ask if you thought this was the right work flow if you have various items in different levels. I'm thinking about an RPG, all of those lootable containers. Would you really make a bool for each in the game instance. If not, someone could just come back to the level and the container would be back. How would you approach the problem on many things to track when streaming in and out many levels?
@MathewWadsteinTutorials
@MathewWadsteinTutorials 8 жыл бұрын
Honestly I wish I knew a "good" answer to this but I have never created a game with such large scope before. If I was approaching something like that it would depend on how large it would be and how I would design it. Let us say you have an RPG with streaming levels (say caves or dungeons) and the layout is fixed along with chests. Each chest would probably pull from a loot table to determine what can drop which means something somewhere would keep track of what chest has which loot table. I wouldn't see a big issue with some form of a master save file that keeps track of things looted like in a key:pair system such as the chest ID and if it was looted or not. All of this could be in a separate file, like a CSV or Data Table, to allow you to easily control what is where. As for saving and loading and looting, if your save game object contained an array of structs (your key:pairs) that was simply added to each time you looted a chest you could use this as a reference when you created the level for spawning "unlooted" chests to prevent chests from being looted twice. By only adding in the key:pair when they loot you can restrict your file size to only being as large as the player needs as they play. Is this the right idea? I honestly don't know. Would I do it like this the first time? You bet I would. If something did not work out right or broke I would see what I could to do fix it and learn along the way =) Actually now that I read this over your save game object wouldn't even need a key:pair or struct. A simple array that has the chest ID (which should be unique) that you update whenever your player loots would solve the issue as it's either in the array (looted) or not in the array (unlooted).
@RyanSturtevant
@RyanSturtevant 8 жыл бұрын
Wow that's an epic answer. Thanks for taking the time. I do have loot list system for lootable actors. I guess the way to go is just an array with the ID's. Would not be too hard. Somehow I hoped that Unreal would just save the state of the level automatically on unload or there would be some kind of option. Not a bad feature request. More annoying is coming up with the logic to run at begin play in the level BP for all things that could be changed. I guess that's not too complicated... Still it all adds up.
@MathewWadsteinTutorials
@MathewWadsteinTutorials 8 жыл бұрын
I am sure you could write a plugin or something similar to do what you want, I know there are plugins on the Marketplace that can do things like a save state. It's a lot of work but might be fun to try if you have the time =)
@GloriaAlMetalOldSkull
@GloriaAlMetalOldSkull 3 жыл бұрын
hi bro how can i keep the objects obtained in the level before to a new level ? thank you so much.
@jiwik731
@jiwik731 Жыл бұрын
Cant find the answear or i am just asking google wrong questions but if i will save data of parent into the game instance will these data be saved also for a child or i have to make separate values in instance for each child? Each child will have different values of these variables.
@powerpc6037
@powerpc6037 4 жыл бұрын
So it's best to use this instance to store all your data you wanna keep during the entire game? Stuff like player's health, mana, experience, level, his entire inventory, quest progression, bosses/monsters killed which aren't meant to be spawned yet and alot more. But that's ALOT of data to store and set back every time you change a level. Why not simply store all that data there permanently and keep it only there? No need to swap back and forth all that data. The inventory can be 150 slots big and there may be over 1000 quests which all have different goals, states and stuff. That would make a huge function to transfer data all the time.
@cosmotect
@cosmotect 2 жыл бұрын
Now to understand why you would use game instance over storing things in the game mode
@ozcanozteke284
@ozcanozteke284 3 жыл бұрын
With the hope of someone seing this: I have created an array to save chosen player classes in a lobby. Players travel to a new level after selecting their characters, the level uses a new game mode. It seems like the length of the array is alright. but if I print out the contents, it's all blank. Is there something special with arrays? Thanks!
@Manim8
@Manim8 4 жыл бұрын
Is there an absolute need for Game Instances? I've been doing everything in the GameMode and SaveGame and all is working well: saving all values during 'Load next Level' stage etc. So is a Game Instance essential or optional?
@VinayakRawas
@VinayakRawas 7 ай бұрын
8 Years Ago.... isnt he The Messiah we Talked about
@emilybrear2601
@emilybrear2601 6 жыл бұрын
In the "get health" part of the blueprint I run into an error on the last "set" node. It won't let me cast a character object reference to a game instance object reference. Implemented the source file and it still threw an error. Think UE4 ver 18 doesn't like it...
@BlogTornado
@BlogTornado 6 жыл бұрын
Hello Mathew. Thank you for all these amazing tutorials!!! I just had a question on how do Game instance and Game save communicate with each other. I know that Game instance likes to collect information but what's not clear to me is how do you get Game Instance information to be saved in to Game save. That would be Score text in particular. Would there be FTW tutorial on these as well?
@mantronicsenterprises
@mantronicsenterprises 7 жыл бұрын
Thank you very much for this, it has made Game Instances much clearer, and how to use them now makes more sense. You mention at 6:40 that you are not using the appropriate way to have the values automatically save and load the player health, do you have another tutorial on the "correct" way to set this up?
@Novalis1504
@Novalis1504 7 жыл бұрын
He always has to get the game Instance and cast it into a GameInstance Object. A better way would be to store a Reference to that GameInstance at BeginPlay or the Construction of the Widget and then use this Reference to access the variable inside the GameInstance. with a library example: He is going into the library to learn something about history. Everytime he wants to do some research for a specific question. He goes to the shelf, searches for the book (get Game Instance), makes sure this is really the book he wants (cast to Game Instance), uses this book for his one question and puts the book back into the shelf, and immediately forgets where the book is standing. So everytime he wants to do some research, he would have to go through this process. With a reference to this book (or Game Instance), you don't have to validate, that this object/book/Game Instance is really the one you need. Maybe that's what he means. I hope I was able to help you out :)
@windflier2169
@windflier2169 7 жыл бұрын
So if I make a RPG game, When I open a new level, I need to store all of things(Like inventory's item,Character state, Character info,etc) into gameinstance, then get it out? This is so complex……
@MathewWadsteinTutorials
@MathewWadsteinTutorials 7 жыл бұрын
There are certain things that are part of the engine and around all the time and other things that only exist when created and needed. Maps/Levels destroy almost everything when they are loaded and unloaded so you need a way to store things on a map change if needed. The Game Instance is an object that is created when the game starts and then destroyed when it ends so it is around all the time and is a great place to store things that you want to persist between loading different maps. An alternative to this would be to use the Save Game and save anything you want to disk before you load the new map as well.
@j.r.vosovic1347
@j.r.vosovic1347 7 жыл бұрын
I am also using an RPG system and would love some help on this. The example I think is not up to date for 4.15+. Any chance you could walk through Item/equipment saving?
@proudarts9127
@proudarts9127 7 жыл бұрын
If you were holding what levels have been completed, will you have to save the Game Instance to disk, would it be better to use the Save Game?
@user47033
@user47033 5 жыл бұрын
Can you get the BP Game Instance in C++? Or do I need to recreate the instance in C++?
@maj2369
@maj2369 3 жыл бұрын
make this with actor please im stuck, when i load my other level the reference is destroyed
@NashMuhandes
@NashMuhandes 8 жыл бұрын
Hi! Very helpful video. Can you do a WTF and/or HTF for things like GameState, PlayerState and GameMode? Thanks for your amazing channel!
@primitivepatterns
@primitivepatterns 3 жыл бұрын
really caught off guard when yr intro audio didn't play as usual lol
@MegaCevapcic
@MegaCevapcic 8 жыл бұрын
Damn you really explain things well :) A disclaimer before the question: All my coding experience comes from the 2 weeks Ive been messing around in UE Blueprints, which is why some stuff flies right through my stupid head. Now for my big-ass question: Ive made a "master blueprint" character with variables from a Structure (which contains integers, text and a boolean). In the Construction Script of that blueprint Ive made an elaborate web that sets all these variables based on a Random Stream, which gets a random seed every time the Construction Script is called(was apparently necessary because the spawned child characters would have the same seed). In the Gamemode BP I spawn childs of "master BP" on EventBeginPlay which spawn perfectly (all variables get set randomly etc.) every time I play the level. My question is basically will all the actors created get their variables "reset" because the Construction Script will fire off again when I reload the level? I was told I wouldnt have to worry about the Construction Script once I hit play -.- If I collect all spawned character via "get all actors of class" in an array I guess I could set them in the Game Instance so they get stored no matter what I do and update them in Game Instance every time their variables change, or do you think its best I just trash everything in the Construction Script and just make a CustomEvent called "Birth" which will set all the variables once the child character "leaves the womb" :P I guess this is more a question about the Construction Script than game instance and sorry for the text wall, I usually prefer asking through comments than opening forum threads, I hope you dont mind :) In any case keep up the good work, your videos are great.
@MathewWadsteinTutorials
@MathewWadsteinTutorials 8 жыл бұрын
+MegaCevapcic The construction script is basically called one time when the item is created. If you are creating them in the editor the construction script is called then. If you reloaded the map with this character in it they would not get the construction part called again due them already being in the map and having it done already. If you create them at runtime, as in spawn an actor, then the construction script will be called in for that one time. So yes you don't have to worry about the construction script once you hit play *if* those things are already in the level. Depending on what you want them to do should decide if you use the script or not. Traditionally the construction script would be used for things in the editor, such as randomizing a look of a building during map building or some other such thing. Have a "Birth" event or function that is called on begin play for the actor might be better if you plan on spawning these during gameplay.
@khydrain
@khydrain 5 жыл бұрын
I don't know what I would if you haven't done those videos.
@MrManet
@MrManet 3 жыл бұрын
You're a life saver, thanks!
@DragonFang253D
@DragonFang253D Жыл бұрын
Can we get a version that is "the appropriate way of doing this"
@LeonHeytens
@LeonHeytens 2 жыл бұрын
Just what I needed
@Odb718
@Odb718 5 жыл бұрын
Thank you for making these.
@platinum3d77777
@platinum3d77777 Жыл бұрын
You SAVE MY LIFE, AGAIN!!!
@inchjan3203
@inchjan3203 6 жыл бұрын
man your tutorial are very good and very well explained. Can i request one tutorial i didnt find it on any of the tutrials! How can i get text on editable text box like for example you want to make it as speed of all the AI or getting it as number of spawn in all target you want to spawn it. ?
@jorhoto7064
@jorhoto7064 5 жыл бұрын
Lets say you are working in an RPG game plenty of levels. Does it mean you need to be constantly storing/loading all your actors instance values? :S
@RWThurman
@RWThurman 3 жыл бұрын
You're as handy as a pocket on a shirt!
@StormyDoesVR
@StormyDoesVR 6 жыл бұрын
Tried to use this to talk between a persistent level and a sublevel in the Robo Recall mod kit, unfortunately the mod kit doesn't allow other instances. oof. xD
@IoSkyBoyoI
@IoSkyBoyoI 2 жыл бұрын
But what about booleans?
@moviemonster99
@moviemonster99 8 жыл бұрын
Sir. I wold like to ask how to reset my coin count back to 0 after restarting a game. I have a PLAY button i my main menu that only opens first level but the coin count does not reset back to 0. My coin bank is stored in my game instance. Could you please explain what i need to add on Play button pressed to open level with reset (00) text coin widget. Sir you are the Best. Thank you.
@MathewWadsteinTutorials
@MathewWadsteinTutorials 8 жыл бұрын
The Game Instance is persistent, it will keep all of the data until the game is closed. The same way you increase your coin count in the game can be used to reset it back to 0. You need to set the Coin Count value in your Game Instance back to 0 whenever the main menu is loaded, or even when you hit the play button.
@BlogTornado
@BlogTornado 8 жыл бұрын
Sorry I already have fixed the problem exactly the same way you suggested with Coin Count value. Thank you for that! How ever these reset now creates new problem. The Coin Count value reset deletes the Highest Coin Count . How can I set up my Coin Count Widget in Main Menu to show only The highest Coin Count without being reset on button pressed. The reset, resets the Game Instance along with the highest score. Mr. Wadstein Please ignore the question below. Could you please explain to me how to keep the Highest Coin Count in Coin Widget without being reset on PLAY. Thank you Sir!!
@MathewWadsteinTutorials
@MathewWadsteinTutorials 8 жыл бұрын
I am assuming you have 2 variables so this should not be much of an issue. Your game Instance can hold both if you want. Coin Count and say Highest Coin Count should not both get reset if you are just resetting one of them. I don't know how you are resetting them but simply setting your Coin Count back to 0 and not touching the Highest Coin Count should leave the Highest alone. Is your Widget not showing the Highest Coin Count and maybe showing the Coin Count?
@BlogTornado
@BlogTornado 8 жыл бұрын
You Sir are exactly right. I do have Coin Count and Coin Bank. Coin Bank is stored in the Game Instance and yes I'm only resting Coin Bank on button pressed with Set Coin Bank (0). So in my Coin Widget I should in Main Menu I should set my Coin Widget in Biding with Coin Count instead of Coin Bank. I think? Please correct me if I'm wrong but I'm gonna try it and will let you know if it worked. Thank You Sir!!
@BlogTornado
@BlogTornado 8 жыл бұрын
Sir. Wadstein. I did as you suggested it's working OK. I added new Integer (HighestCoinCoins) and replaced with Coin Bank. What I did is add another invisible coin on top of other. Main Menu has it's own Coin Widget and Levels have their own. So visible coin goes to the levels Coin Widget and invisible one goes to Main Menu Coin Widget. So everything OK there except that lets say I collected 10 coins they go to main menu and then I play again and reset the coin in the level and when I collect lets say 5 more then on reset they are added to the 10 coins. So coins from the new game started are now added on top of the 10 ones stored in the Game instance. They should not be added but instead added only if I surpass the 10 coins collected. Sorry I'm kinda complicating here. Cant quite visualize whats going on here. If you could Please shed some light on these Sir. I would greatly appreciated. So how would you set it up if you had one coin on top of each other one going to the coin count and another going to another Coin widget in main menu. So I'm only erasing coins inside the levels on button pressed and not the one in Main menu Which is also stored inside Game Instance. Sorry about the long explanation. Thank You.
@thankyou991
@thankyou991 2 жыл бұрын
Thank You
@setams4957
@setams4957 4 жыл бұрын
you were so usefull thank you
@rahultandon9749
@rahultandon9749 2 жыл бұрын
superb
@hallo-welt
@hallo-welt 7 жыл бұрын
Excellent thanks
@umbakarnask3844
@umbakarnask3844 6 жыл бұрын
Sorry but something is wrong. Probably old version of the engine because I cannot accomplish what you did with "Cast to FrameworkCharacter"
@legacystudio1119
@legacystudio1119 6 жыл бұрын
Thank you!
@angrybonobro8711
@angrybonobro8711 6 жыл бұрын
Usefull tuto !
@itanshi
@itanshi 3 жыл бұрын
Oddly your game project file has been stuck on 39% for some time now. even so, thanks for the great tutorial. Ill just retry it. eh, its stuck guess it needs an update for 4.26 edit: ok i restarted pc, it loaded ok
@DimitryArsenev
@DimitryArsenev Жыл бұрын
Its looks unusable. I need more classes to store variables between levels. Example: quests - for store quests, items for store items, and etc. Some components for Game Instance, but it not support components.
@xavierloux
@xavierloux 8 жыл бұрын
Thanks
@theshrk8977
@theshrk8977 6 жыл бұрын
thanks
HTF do I? Whiteboxing with BSP in Unreal Engine 4
34:35
Mathew Wadstein Tutorials
Рет қаралды 8 М.
HTF do I? Event Dispatchers in Unreal Engine 4
11:00
Mathew Wadstein Tutorials
Рет қаралды 113 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
HTF do I? Use the SaveGame Object in Unreal Engine 4
10:02
Mathew Wadstein Tutorials
Рет қаралды 48 М.
WTF is? The best thing to use?
13:45
Mathew Wadstein Tutorials
Рет қаралды 15 М.
Unreal Concepts - Persistent or Saveable Objects ( UE4 )
28:02
Mathew Wadstein Tutorials
Рет қаралды 21 М.
Epic's Unreal Optimization Disaster | Why Nanite Tanks Performance!
13:07
Threat Interactive
Рет қаралды 295 М.
UE4 Tutorial: Class Explainer
16:04
underscore
Рет қаралды 26 М.
The Unreal Engine Game Framework: From int main() to BeginPlay
27:22
Alex Forsythe
Рет қаралды 222 М.
HTF do I? Create a new Project Template in Unreal Engine 4 ( UE4 )
13:15
Mathew Wadstein Tutorials
Рет қаралды 10 М.
Stop Casting! use blueprint Interfaces Instead!
11:56
The Game Dev Cave
Рет қаралды 14 М.
HTF do I? Level Streaming using Volumes in Unreal Engine 4
9:49
Mathew Wadstein Tutorials
Рет қаралды 35 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН