What Is A Game Instance And Why You Need One - Store and set variable info between UE4/UE5 levels

  Рет қаралды 22,158

GDXR

GDXR

Күн бұрын

Updated Discord invitation: / discord #UnrealEngine #VR #VirtualReality
► Join the Discord: / discord
► Description
Covering how to use the UE4 game instance and why you should use it with setup examples.
Event Dispatchers
• How To Use Event Dispa...
-----------------------------------------------------------------------------------------------------------
► Patreon: / gamedevxr
► Twitter: / gamedevxr
► Instagram: / gamedevxr
-----------------------------------------------------------------------------------------------------------
If you're new to VR and want to get started with Oculus Quest development, I recommend watching these videos first.
1. Installing UE4 from Source code (contains more up to date Quest features)
• Installing UE4 4.25 fr...
2. Installing Android Studio (Required to create Oculus Quest projects in UE4.25+)
• Installing Android Stu...
3. My Oculus Quest 1 Settings (These are different to the Quest 2)
• My Oculus Quest 4.25 B...
4. My Oculus Quest 2 Settings
• Quest 2 Settings You S...
-----------------------------------------------------------------------------------------------------------
PC SPECS:
► RTX 2070 Super
► I9-9900K
► 32GB Ram
► 2TB SSD
Equipment
► Keyboard: HyperX Alloy Origins
► Mouse: Anker® Ergonomic Optical USB Wired Vertical Mouse
► Mic: Trust GXT 232
► WebCam: Jelly Comb
► Screen: AOC I2367fh 23-inch LED x 2
► Headset 1: Oculus Quest 128GB
► Headset 2: Oculus Rift + Motion Controllers
► Headset 2: Oculus Quest 2
► Graphics Tablet: Wacom Cintiq 13hd

Пікірлер: 55
@IrocZIV
@IrocZIV 2 жыл бұрын
I like that you explained the why, and showed some issues that you might experience. It is a bit long, feels like it would have been a good livestream, and then a more concise video could be made from it after you worked out the bugs in the presentation. Thanks for the video.
@GDXR
@GDXR 2 жыл бұрын
If this was a live stream it would have been much longer lol.
@immortal3164
@immortal3164 9 ай бұрын
did i ever told you how much i love you? You are helping so much, great work, great explanations.... continue as you do!
@stoneageprogrammer432
@stoneageprogrammer432 Жыл бұрын
Hey this is a cool video and I've subbed you. I've been studying GameInstance lately, but I'm still very new to GameDev and Unreal. I'm making a game with multiple levels, and discovered that the gun that I found in one level does not transfer into the next level. So I discovered GameInstance, but I still don't know how to code that. I got a note from another dev who described the logic. Here is what he wrote: "Gameinstance is like this. 1. You create a Gameinstance. 2. You set in Project Setting to use your Gameinstance. 3.Before you switch a level you save all what you want keep to the Gameinstance. 4. After you switched the level. You call the Gameinstance and load all the things which you saved in the Gameinstance back to the new level. I don't know how you make an inventory System but I think they use data tables. Lets make an example with your gun. Lets say step 1 and 2 you did. Step 3 is : Save the gun mesh in your GameInstance as a gun mesh variable. 4. You are switching the level. In the new level you need set your gun mesh. So you call your Gameinstance, find the saved gun mesh and use this saved gun mesh to set the gun mesh in the new level. Now your new level has the gun from before. I am not sure if this is the best way but as a start point it should work." Like I said, I don't know how to turn that into Blueprints. Do you think you might do another tutorial demonstrating this procedure?
@jazzypizzle
@jazzypizzle 6 ай бұрын
Super understandable and well explained. Thank you sir!
@FlockersDesign
@FlockersDesign 7 ай бұрын
Its funny when he says his is just from the top of my head When he reads the documentation from Unreal them self about GameInstance😂😂
@GDXR
@GDXR 7 ай бұрын
The examples are off the top of my head.
@TheD3vilHimself
@TheD3vilHimself 2 жыл бұрын
Bro, Nice Shirt! I see you are a man of class and style.
@commandingsteel
@commandingsteel Жыл бұрын
Thank you Sir!...took me a little bit to integrate it into my project, but now I'm well under way into having a functional game instead of just a level cheers
@TheJesusjones
@TheJesusjones 2 жыл бұрын
Amazing video Jonathan - very well explained and demonstrated!
@sebastianosorioarango6270
@sebastianosorioarango6270 Жыл бұрын
I dont understand the minute 19:00, i have to create a custom event in the GI or in the ThirdPersonCharacter BP?
@emptybruh
@emptybruh Жыл бұрын
If you are going the custom event rount, you make the event inside tpcharacter, attach everything you want to that event than cast to tpcharacter bp inside instance and run said event on Event Init
@StormFrontGame
@StormFrontGame Жыл бұрын
thankyou, this has helped alot!!
@chasesommer
@chasesommer Жыл бұрын
If the variables are not showing up at 10:00, try setting Health and Stamina as text instead of integers. That's working for me now in 5.2. I'm sure there's a better way and would love some feedback!
@Pierraxl
@Pierraxl 8 ай бұрын
Why don't you just plug the "As game instance " from the cast directly into the Set integer ? Instead of creating a variabale et get it again right after ? thanks
@sams_3d_stuff
@sams_3d_stuff 2 жыл бұрын
Hey! Love your videos!
@GDXR
@GDXR 2 жыл бұрын
Glad you like them!, Thank you.
@amitbeharier5698
@amitbeharier5698 Жыл бұрын
Amazing. Thank you!
@FDOF_Dev
@FDOF_Dev Жыл бұрын
Question... why not just reference your game instance at begin play and then get that reference, and pull off of it and setting the desired variables directly as they change? And then you could use those variables from the game instance directly for your binds in your widget, right?
@FDOF_Dev
@FDOF_Dev Жыл бұрын
Oh thanks BTW. The part about how event dispatchers and how using an object reference in the game instance instead of checking from each chest, solid advice. Well explained.
@GDXR
@GDXR Жыл бұрын
So this isnt a bad way of thinking about it however it can cause issues. For example if your game instance loads first and you then your setting variables it can cause other things refrencing it to pull null values because they havent been set yet. For example UI. Is your player spawns and has a ui set on begin play. the UI can comunicate to the game instance. But if the player spawns, cast to the game instance and then sets a variable. It's possible your UI has already spawned before the game instance sets the variable. So if the UI is trying to access something that hasnt been set yet. It will break. You need to consider the load order of things.
@FDOF_Dev
@FDOF_Dev Жыл бұрын
@@GDXR oh okay. Cool. Thanks for the heads up.
@katiekaliber
@katiekaliber Жыл бұрын
@@GDXR Thank you, that makes a lot of sense.
@KavanBahrami
@KavanBahrami 2 жыл бұрын
25:10 reminding you to link the event dispatcher video in the description ;)
@GDXR
@GDXR 2 жыл бұрын
Thank you.
@OpenMawProductions
@OpenMawProductions Жыл бұрын
So, if you're making something like a first person shooter, you would have to save: Player health, player armor, player inventory, current weapons that have been picked up, current ammo for each weapon, current ammo in each weapons magazine (if they have that)... All in the game instance? Doesn't this start to get a little... Insane? Or am I just not understanding this correctly.
@GDXR
@GDXR Жыл бұрын
No, your correct. You add all the variables you plan to save inside your game instance is it's a persistant actor (Not destroyed between levels). Then inside the game instance you have a create save game object. Which you then pass the variables through to. But yes, with blueprints, this get's, Insane.
@mch43856
@mch43856 Жыл бұрын
really helpful thank you!
@gordon7936
@gordon7936 10 ай бұрын
Is casting to game instance good idea If I need to have variables that i might change every frame? I'm told casting is not great for performance, so what's better way to keep global variable, even per level, not the whole game?
@GDXR
@GDXR 10 ай бұрын
So the game instance is where you will want to keep global variables, however these can also be stored in Structs to stop the game instance having to much to manage. For the casting, casting to the game instance isnt bad, it always exhists so the game instance cast will never fail. however seting variables inside the game instance on tick/ever frame is a bad idea, You should only send information when you really need to and its unlikely that the game instance needs to know this amount of data.
@gordon7936
@gordon7936 10 ай бұрын
@@GDXR Thank you for your answer. For what I know I still have to keep the struct as a variable in some place. I hoped there's some way to have a global variable, like the material parameter collection, that I can easily access anywhere, but I see that's not possible with pure blueprints.
@KerryCronic
@KerryCronic Жыл бұрын
I'm only having an issue with one item. Which is the first person rifle component. Everything else seems to transfer fine but the rifle does not. Any idea how to fix this? The bHasRifleVariable is still stored when i changed levels but the rifle itself is gone.
@thehotpotatosquad
@thehotpotatosquad 9 ай бұрын
You need to store the rifle as actor object reference, or enum from where you chose the actor to spawn.
@thereanimator6072
@thereanimator6072 2 жыл бұрын
Great video! My player has 18 variables I need to store between levels. Do I need to create a custom event for each variable or can I use a sequence perhaps? Thank you
@GDXR
@GDXR 2 жыл бұрын
If you have multiple variables, all 18 should be stored in your game instance. From there you can create a system so the actor on begin play casts to the game instance (Same code as the thumbnail) and then sets the variable you need. Your actor should only grab the variable they need.
@ogradus
@ogradus Жыл бұрын
I could be wrong, but isn't the PlayerController also persistent also?
@GDXR
@GDXR Жыл бұрын
Player controllers are persistant between levels but in most cases are only used when your dealing with multiple players/characters/possesion. The game instance is normaly used by devs doing single player content.
@ogradus
@ogradus Жыл бұрын
@@GDXR that is a relief! There are so many tools and it's hard to know what is good for certain things. It makes more sense to use a game instance, but I suppose I can make this work. I'm making an RTS and I've been wondering if I can save all the stats/locations of selected units by using object references, which I've stored in the player controller. I'll let you know how it goes. Thank you for your response!
@rubenminasyan9801
@rubenminasyan9801 2 жыл бұрын
thanks so much
@katiekaliber
@katiekaliber Жыл бұрын
Oke i was good with everything until you started doing the initialize in the instance and then told us to call it in our player blueprint while doing something different yourself, i can't for the life of me figure out what you mean by that because i can't call upon that custom event from my player if made in the instance. Could you explain what you meant?
@DimitryArsenev
@DimitryArsenev Жыл бұрын
I need more when 1 Game Instance. I cant make all logic in one class. How its can be fixed?
@GDXR
@GDXR Жыл бұрын
you can only have one game instance, you will need to implement a character possessions system and look into the Player Controller Class
@DimitryArsenev
@DimitryArsenev Жыл бұрын
@@GDXR No thanks. Example - i make logic for sql database - its not Player logic. Now i just use static classes - i init it in game instance class. Also i think possible make many Game Instances - its subcomponents logic, but i not try it.
@ionthedev
@ionthedev 11 ай бұрын
​@@DimitryArsenev unless you customize the engine, you can't have more than one game instance, as each time a packaged application made in in unreal is ran, the game instance is created on the opening of the application and is destroyed on closing the application. That is just how unreal works For your use case, which I've done something similar with Mongo, is to just write the data directly to the database instead of storing it in the game instance directly.
@DimitryArsenev
@DimitryArsenev 11 ай бұрын
@@ionthedev I just use UGameInstanceSubsystem, its way to have unlimited game instances.
@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.
@jaybenny5477
@jaybenny5477 2 жыл бұрын
hi im a student and preparing for a competition about vr development(make a scene that has interacitve functions,character,animation,level designs ) ,sametime, has a UI platform . The subject is about learning English,also my idea is to grab the letters from one box to combine a word on a screen as a beginner idk how long it would cost (i must finish it in 1 mouth) and is there any courses help me study this ?
@jimmypi2035
@jimmypi2035 2 жыл бұрын
Great tut, thank You. May I ask, what if we store some values/variables in actors and pawns that are dynamically spawned as the game progress? How to cast to those objects even if they are not in the scene yet :| :??? hlp
@chas3818
@chas3818 2 жыл бұрын
Thanks for the vid, got it working with my health which is great. How does this work with Actor Variables? For context I have a sword blueprint being saved as an actor variable thats being attached to my player, and I followed the same sort of set up as the health where it calls the event dispatcher to update when you pick up a sword but no luck, returns is not valid so the variable isnt loading on begin play
@studiobaxter1242
@studiobaxter1242 8 ай бұрын
Wow, thank you. Been building my game for a year as a total beginner. Only ever had one level until last week, but was a bit lost as to how to progess. Just got something to save between levels and am feeling elated! Subscribed.
@ROSALIEIK
@ROSALIEIK Жыл бұрын
dont get it
@GDXR
@GDXR Жыл бұрын
If you have a variable that needs to be stored between level loading. Then you need a game instance to store the values. Let's say your player has been damaged and there health is currently 32%. If you load a new level there health value will reset to default 100%. So storing the health inside the game instance means, when you load the next level. There health will stay at 32% and won't be reset.
@rossedwards5724
@rossedwards5724 2 жыл бұрын
A very clerar tutorial, thank you
@GDXR
@GDXR 2 жыл бұрын
Glad it was helpful!
@lz4090
@lz4090 2 жыл бұрын
Very helpful. Could you also do a game mode tutorial? Thank you
LIFEHACK😳 Rate our backpacks 1-10 😜🔥🎒
00:13
Diana Belitskay
Рет қаралды 3,9 МЛН
Players vs Corner Flags 🤯
00:28
LE FOOT EN VIDÉO
Рет қаралды 67 МЛН
Worst flight ever
00:55
Adam W
Рет қаралды 26 МЛН
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 10 МЛН
How I Remade MW2 with Unreal Engine 5
12:37
reubs
Рет қаралды 3,1 МЛН
I solved Unreal Engine's Package Size Problem...
14:35
Cobra Code
Рет қаралды 74 М.
Save And Load If An Actor Is Destroyed - Unreal Engine 4 Tutorial
23:24
I Struggled With Blueprint Interfaces for Years!! (Unreal Engine 5)
16:48
Glass Hand Studios
Рет қаралды 185 М.
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 591 М.
Demystifying Soft Object References | Inside Unreal
1:27:51
Unreal Engine
Рет қаралды 84 М.
Tierlisting the BEST (and worst) GAME ENGINES
33:51
BiteMe Games
Рет қаралды 225 М.
Blueprints vs. C++: How They Fit Together and Why You Should Use Both
47:14
Inheritance Hierarchy And Class References - Unreal Engine 5 Tutorial
28:00
Pitchfork Academy (MizzoFrizzo & Co.)
Рет қаралды 1 М.
HOW TO USE EVENT DISPATCHERS FOR PUZZLES IN UNREAL ENGINE 5
34:12
LIFEHACK😳 Rate our backpacks 1-10 😜🔥🎒
00:13
Diana Belitskay
Рет қаралды 3,9 МЛН