UE5 - Data Storage Using Object Class

  Рет қаралды 8,040

3 Prong Gaming

3 Prong Gaming

Күн бұрын

Пікірлер: 55
@NeatWolf
@NeatWolf 11 ай бұрын
Hi - thanks for the video! I noticed some people are suggesting to use the GameInstance as a container for global game data but - is it good practice in Unreal? What would you recommend to avoid falling into the trap of Singleton? (I get the answer can be very situational)
@ShortBusTrip
@ShortBusTrip 11 ай бұрын
Hey thanks for the comment. Basically, in a single player game you can do what you want but in a multiplayer you really should use each base class as it was intended because of how unreal handles replication. I see the allure of using the game instance for such things because it’s easy to grab a reference to but it’s poor OOP design. There are much better ways to organize and store data than to house it all on a game instance. The game instance is already a heavily used class responsible for a lot of tasks in the background that to burden it with mundane data storage and retrieval is bound to cause lag issues
@BenskiGameWorks
@BenskiGameWorks Ай бұрын
Hey! I would love to hear your take on using a Primary Data Asset to store a single object reference to make it have "Class Static" behaviour or "Global" behaviour. So I thought using an object just like you have shown here will work for me, but since it needs to be constructed per Owner it doesn't work unfortunately. I'm using Blueprints to create an actor component that is modular and can be added to any actor in any UE5 project. The catch is, I want all these components to share a variable of type reference to UserWidget and be able to read/write to this "shared" variable. MMy solution right now is I created a Primary Data Asset that just has a reference to the desired widget and it works pretty well to be honest. But I'm not sure about this solution in terms of optimization/best practice. Thanks
@ShortBusTrip
@ShortBusTrip Ай бұрын
I understand what you are trying to do here but it's important to understand a few key terms. Static means by its very definition "not changeable" so using a static class will not work for something you wish to let multiple objects manipulate. In using C++ there are ways to share pointers as to minimize having many references to the same object hording memory but as far as I know, this behavior is not transferable to blueprints. There are a couple of ways to work around these limitations but none are really "best practice" or even optimized. You can just have a single reference on your player or controller then create an interface that will manipulate the widget with no extra hard references - you simply call the global Player Character or Player Controller and plug it in as the target of your interface call. That's probably the easiest method that is pure blueprints. There is also a way to create a global class, such as the Player Character, Controller, Game Mode, Game instance etc that can be globally accessed like those mentioned but that isn't really optimized and probably not best practice in this situation. A work around that would be to create something like a "level manager" and drop it in the level, storing your "global" variables on that. Then your component can look for this class, store that reference (or find an alternative to store the reference) and using that to access your "global" variables. There really isn't an elegant solution to what you want to do but ultimately, I would consider the first suggestion with the interface on the player or controller. They're globally accessible without cast or hard references and they really should be the classes that decide what to do to the player UI.
@BenskiGameWorks
@BenskiGameWorks Ай бұрын
@@ShortBusTrip First, huge thanks for the detailed answer!!! Unfortunately I cannot allow my Actor Component to be dependant on any object that "doesn't belong to it" like the game Instance or has to be spawned like a manager etc, it's a plugin and I want it to be as modular and easy to use (download and throw the component on an actor in the scene). Second, just to be more precise about what I meant by "Class static" from C++, if I'm not wrong: When a variable is defined as static within a class, then this variable can function like a "Shared variable" between all instances of that said class i.e. a variable that is global in the scope of all instances of said class. That is the behaviour I'm trying to achieve, a reference that is shared between all instances of said component.
@YourJudgement-ms7kv
@YourJudgement-ms7kv Ай бұрын
So just to be clear. This isn't a dynamic data storage? Just static? Man I was really hoping for something that I could put all my booliens in for unlocking parts of a level (also make it easily savable so the player doesn't have to keep unlocking them). I know that this object class system you have isn't saving data, but I was hoping for something that had all the data in one area, can be edited. Like how at 12:26 you attempt to set the health variable but are unable to. And then easily save it. All the while having it easily accessible to other actors. I want to try and avoid spaghetti blueprints and actors if that makes sense. Any ideas? Also thank you for the video! It's very helpful!
@YourJudgement-ms7kv
@YourJudgement-ms7kv Ай бұрын
Thinking about it more I might just go with MPCs. Maybe have one blueprint that triggers them and stores what they are and use MPCs to communicate it. (also i'm posting this here so maybe someone else might use this idea.)
@ShortBusTrip
@ShortBusTrip Ай бұрын
@@YourJudgement-ms7kv correct this is just another way to store static data but is more flexible than other methods. For what you want just consider using the game mode to track all your bools as long as they are general/generic variable that are universal. If it’s player direct stuff then consider using the player controller to store them all on. You could also create a blank class and make it like a “manager” class that just sits in the world and does nothing but manage those variables.
@ShortBusTrip
@ShortBusTrip Ай бұрын
@@YourJudgement-ms7kv not sure what you mean by MPC?
@YourJudgement-ms7kv
@YourJudgement-ms7kv Ай бұрын
@@ShortBusTrip Material Parameter Collection. You can easily use it to transfer floats and it doesn't hard reference. Granted its a one way street. It does not activate anything. All you can do is retrieve it. Also thanks for the tips! I'm gonna go look those up right now!
@YourJudgement-ms7kv
@YourJudgement-ms7kv Ай бұрын
@@ShortBusTrip Hey just wanted to let you know that I'm going with a combo of the game mode (like you mentioned) and a save system that leafbranchgames made. If your interested in looking up his system of saving. I know your probably busy but just thought id mention it if your interested! Thank you so much for helping me and all the others!
@PLYATC
@PLYATC 9 ай бұрын
HI) sometimes before i build inventory system on objects, but there is some problem - replication? can i replicate them? and can i save them localy?
@ShortBusTrip
@ShortBusTrip 9 ай бұрын
You can replicate almost anything but I do not review multiplayer in my videos, sorry
@PLYATC
@PLYATC 9 ай бұрын
@@ShortBusTripeven this objects? because when i try this earlier it doesn't work(
@ShortBusTrip
@ShortBusTrip 9 ай бұрын
@@PLYATC yes but from the sounds of things you have some more learning to go. Multiplayer is complicated. I recommend you practice making a single player game first before trying to learn multiplayer
@PLYATC
@PLYATC 9 ай бұрын
@@ShortBusTrip thanks, but i do what i do, i already have workable version on multiplayer, now i try to integrate objects again like do it before on my inventory equipment system (single) but array of objects from savegame disapear when i transfer on server to verify it. Event give back empty array
@lospe85
@lospe85 Жыл бұрын
So... everytime you hit F, you are creating an object in memory, right? can you "destroy" the object later (if you saved the reference somewhere)? I'm planning to create my inventory system using an array of Item Master Object (instead of using struct arrays), so I would be keeping the references. I want to make sure I can destroy/delete/kill those objects once they are no longer needed or consumed. thanks!
@ShortBusTrip
@ShortBusTrip Жыл бұрын
Yes you’re loading the object into memory. Technically when you store the class in a variable (the purple not pink) it is loaded into memory. Constructing it creates a new object in addition to the hard reference class. If you save the constructed class object, just deleting all of its references will send the object to garbage collection. Be careful, too much of this and you can overload garbage collection if you construct and remove objects too quickly which keeps memory loaded until garbage deals with it. Your idea seems interesting and I’d be interested in knowing how it turns out. I would consider using class and/or object soft references in you array. This way, it won’t load each class/object into memory until the exact time you need them and it auto garbage handles them as soon as it doesn’t. Little more work to use them but it’s the most optimized way. If you are going to have thousands of objects especially. Good luck, let me know how it turns out!
@ShortBusTrip
@ShortBusTrip Жыл бұрын
Also in case I didn’t answer, storing each class/object in memory, even as just a variable hard reference, loads that class/object and all it’s dependencies just for that variable. Constructing from that variable creates an addition memory address for each item you construct or spawn. The newly created objects will delete when you remove its reference but you variable will still contain its memory usage. That’s why soft references are the way to go
@lospe85
@lospe85 Жыл бұрын
@@ShortBusTrip thank you so much for your answers!!!
@Lazy_Watcher
@Lazy_Watcher Жыл бұрын
I have actually just finished creating an inventory system using class as a base, and it's all great, but I've come to a small roadblock. I'd like to have the items rave random stats. So maybe an armor would have 3-10 strength randomly when generated. Because everything is stored as a variable class, instead of object, is there any way for me store / get the information I had generate? Or what I would need is an object based inventory system instead of a class one?
@ShortBusTrip
@ShortBusTrip Жыл бұрын
I’m guessing your class based inventory is similar to the object based where in neither are actual objects in the world? In this case I would recommend keeping something like a single “stat manager” BP that is persistent in the world during the entire session. Generate random values for whatever you want and store them in there and call on it when you need it. What I would do is have a random value generate for each item type you want, store it on the manager then create getter functions. This value would then be multiplied against the items base stats. Just a thought
@karthigamoorthy8701
@karthigamoorthy8701 2 жыл бұрын
I'm a newbie, correct me if I'm wrong. So if i have to store 5 different values for the same variable, do I need to create that many child classes?
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
Why would you need to have 5 different values for the same variable? You would need to create a new object (child class) for each type of item. So in this instance it's for an inventory system. So if I want bread, one object (child), water a different object and so on. If what you mean would be to have 5 different types of bread and wanted to use the same object (child) to hold the information for each type of bread then that gets a little trickier but not impossible. Some solutions to that problem would be to possibly use a Struct to hold the different values then get just that part of the struct for the value you need at that time or you could make an array which would essentially do the same thing as a struct in this example. However, given all this extra information, it is not possible to dynamically change the values of a variable on an object class at runtime because the object doesn't technically exist nor can it ever exist. Objects in Unreal can not exist in the world, this is where Actors come in. Things must exist in the world in order to manipulate it at runtime. Using actors to store data is inefficient and will quickly bloat your project and slow it down. This object/data storage solution is a way to store and retrieve static information. Hope this helps a little. You can join the discord and you can get more detailed help/solutions not only from me but the rest of my community. I'm also using this system in my inventory system so if you want a little more clarity then please, check that series out. It's still a work in progress but I look forward to you following along!
@mykhailosaienko
@mykhailosaienko 9 ай бұрын
No, you would create an _array_ of instances of this class and manipulate them using an index in that array.
@ShortBusTrip
@ShortBusTrip 9 ай бұрын
Incorrect. The point of this system is to not create a bunch of instances of your items. Item classes are meant to be used statically. This is how I designed it. To create an array of instances of all your items defeats this method
@TheLord7even
@TheLord7even 2 жыл бұрын
I'm just thinking about replacing the items (actors) in my factory game with objects. but then I would need static mesh actors to display them in the world. Would that be still better for performance as using normal actors? The inventory itself is not that of a problem but there are so many actors (items) on the screen that it can cause performance issues. Well anyways: Great idea and well explained! Thank you sir! :D
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
If you’re running a lot of actors just as items it can be quite a bit. However if you need the items in the world then you need them as an actor. What I will do in the inventory system is make a single actor blueprint that will be “dropped” items, items in the world, and it will get its information from the object class. The object class will just tell the “dropped item” actor what static mesh to use, plus whatever other values it would need. But if I had say 10 items in the world it wouldn’t matter if the actors were from my idea above or if they are their own independent actor. However storing the reference to the actors will be a memory hog because every actor you’d store a reference too is memory that must be reserved. If it just stores the class in an array then you just ask the class for info when you need it. There’s no real memory reservation for that. Hope I made that clear. Hit me in discord if you need more/better clarification
@TheLord7even
@TheLord7even 2 жыл бұрын
@@ShortBusTrip Thank you very much for your informations. I thought about the same, using only one actor and then gather the information from the objects. I know exactelly what you mean. I'll give it a try. Even if it dosn't push up the fps, saving memory is always a good idea!
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
Yep anywhere you can save milliseconds. The larger the project gets the more corners you have to cut to save speed. Taking optimization into consideration early will save headaches down the road
@djkwon9999
@djkwon9999 2 жыл бұрын
Thank you for share! Structure is so annoying. it looks good but how about Garbage Collection? GC would list object and track. if i construct 10k object it could be burden, would it cause hitching?
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
It shouldn’t cause any problems. Objects don’t have any tick so there shouldn’t be any performance issues. You don’t traditionally spawn these into the world either so no performance there. Having 10,000 items would really only cause the files size to be larger. These are merely data containers
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
I’m using this in my inventory system. Check out those videos to get an idea of how I utilize this method
@djkwon9999
@djkwon9999 2 жыл бұрын
@@ShortBusTrip thank you for your response!
@vegitoblue2187
@vegitoblue2187 Жыл бұрын
What about Data Assets?
@ShortBusTrip
@ShortBusTrip Жыл бұрын
Data assets are a reasonable way to store data but they aren’t as flexible as using objects such as calling functions. I’m just presenting another option for storing data but using objects is a pretty flexible way to store data while keeping overhead down but of course it’s not the only way
@vegitoblue2187
@vegitoblue2187 Жыл бұрын
@@ShortBusTrip Well, one drawback of data assets is indeed the fact that you cannot store pointers and other runtime data. Lyra does a hybrid approach, Abilitiy Set per weapon is stored in a UObject
@ShortBusTrip
@ShortBusTrip Жыл бұрын
Yeah. Like I say often and possibly even in this video is there more than one way to do things. Often times you need to do hybrid to accomplish your tasks. Can’t really store pointers in an object class either because the object isn’t instantiated. You can construct an object and then store a pointer on it but then you might as well just use an actor at that point. Object classes do work differently in c++ too though
@ty_teynium
@ty_teynium 2 жыл бұрын
I wished this was covered for UE4. I see a few videos, but I'm still not entirely sure I get it.
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
It should be the same in version 4. What aren’t you getting
@ty_teynium
@ty_teynium 2 жыл бұрын
@@ShortBusTrip Basically I wanna see how far I can go with it; also Would there be any drawbacks to it holding data or calling functions to or from it/them? At the moment, I use mainly actors with variables in them which I'm comfortable with so far. So with objects I wanna see what limitations there may be. Let's say I make a hover vehicle and I want to make two types: one that the player drives, and the other that the AI or CPU drives. How does making an actor of the two differ from making an object of the two? Sorry for long question, but I'm really ready to do this!
@ShortBusTrip
@ShortBusTrip 2 жыл бұрын
Well remember the object isn’t “alive” so asking it to do much would be difficult. It’s just a base class so there isn’t much functionality to begin with. If you have a lot of functions or a lot of data that you need to be persistent and/or be able to change dynamically then you should stick with the actor class
@Cpt.Tripps
@Cpt.Tripps 2 жыл бұрын
@@ty_teynium the method is not meant to replace actors, it's meant to replace structs for data and variables storage.
@ty_teynium
@ty_teynium 2 жыл бұрын
@@Cpt.Tripps okay. Sorry I confused it with Actors. Okay, sorry for late reply, but I set up an Inventory Object that'd contain all the variables for an item and details ie name quantity, max quantity, consumable etc. Not sure what to do with it now.
@pakoo7715
@pakoo7715 Жыл бұрын
In my system i faced with couple of problems: 1) objects are better then structures but still annoying - u have to reconstruct 'em, construct every time, u want to update them, update item master class... a big problem when u want easily add an item to the chest before spawning, u have to do many manipulations, construct many objects an so on... but 2) second problem is much more annoying! Saving and Replication - lots of problems with it! In demonstration projects u will never face with it, but when ur game has tons of items, each item does different staff, ur inventory is complicated - it is really hard to manage everything. Moreover, just like in work with structs, if u need some special variable to be added in ur system, u have to add it in ItemObject, refresh every function where u construct or save, or adding item, make shure all ur widgets works correctly - it's hard. But it is still beter than storing actors and say bye to ur RAM and CPU cache, and structs, where on the one hand u have to manage with tons of useless information inherited from this struct in each item and deal with uncomfortable pins in ur nodes... I heard smth about data assets, but have never seen someone actually uses them... the most interesting q-n is how the others deal with that, why don't we see such problems in deffrent games, especially those where we can modify everything... may be Lua hiding all that staff, or alies...
@ShortBusTrip
@ShortBusTrip Жыл бұрын
I don’t understand all your comment but you are not meant to construct the object at all. In none of my videos have I constructed one of the objects. It’s meant to hold static data. You are not meant to use the data objects in that way. If you are going to construct the objects and manipulate the data you might as well use actors. This system is not meant for that. Constructing the objects will be meant for only calling functions like “use item” on the object and that’s it. It sounds like what you’ve done is nothing similar to what I’m demonstrating in this series
@pakoo7715
@pakoo7715 Жыл бұрын
@@ShortBusTrip sorry for my English, i am not a native speaker, typing on phone outdoors in -19 °C :) i just described my personal troubles in my system where i have this base ItemObject which is a storage of different variables. I also have master item actor where in construction script i construct object from BaseItemObject class and set all the variables from my master item and than i save ItemObjRef and work with it
@ShortBusTrip
@ShortBusTrip Жыл бұрын
But what I’m saying is you don’t want to use objects as dynamic objects. You might as well just used actors if you’re changing variables on them. However you can construct the object and store its reference in an array an manipulate it that way too but again this isn’t great practices and it all defeats the purpose of using objects to store data.
@pakoo7715
@pakoo7715 Жыл бұрын
@@ShortBusTrip yes, agree. I watched a couple of ur videos and it looks really comfortable to work with. But i have a q-n. For example i have some equipment items like backpack or vest. Those items has their own inventories which i gonna be using to store everything. The idea is to pick up and automatically equip this item in my slot what gives the opportunity to pick up and store other items in the inventory. In my system i just add array to each specific actor and in my base object as well, then i can grab this referece in my InventoryComponent. But if i will use ur system, i cannot do it whitout casting. Moreover, i cannot attach Inventory component to them, coz when i pick up those items actor and attached component destroys. Could u help me to deal with that problem?
@ShortBusTrip
@ShortBusTrip Жыл бұрын
@@pakoo7715 to be honest your thing seems kind of a mess. You don’t need an actual item spawned to use or equip items. You just need their information which are the values they hold. You can get this information without casting anything. To automatically equip an item just have the item go to that slot of your inventory. It’s really hard to say how your project looks so I can’t really give you a perfect answer. If your system matches my system I could give a better answer but unfortunately I don’t know how you are doing your code
Smart Data Storage -- UE5 Blueprints
14:50
Slightly Esoteric Game Development
Рет қаралды 6 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Epic's Unreal Optimization Disaster | Why Nanite Tanks Performance!
13:07
Threat Interactive
Рет қаралды 297 М.
The Right Way to Spawn Objects in Unreal Engine | UE5
18:03
Ali Elzoheiry
Рет қаралды 37 М.
Why do Studios Ignore Blender?
8:52
Film Stop
Рет қаралды 391 М.
The Game That Hacks Your Brain
24:43
camwing
Рет қаралды 1,2 МЛН
How To Make A Game Alone
8:11
Thomas Brush
Рет қаралды 1,2 МЛН
Unreal Engine Data Assets EXPLAINED
11:23
The Game Dev Cave
Рет қаралды 10 М.
5 Tricks you (probably) don't know about Unreal Engine 5
10:44
Cinecom.net
Рет қаралды 404 М.
This next-gen simulation for UE5 is insane...
20:49
Bluedrake42
Рет қаралды 351 М.
The Most Common Mistake Beginners Make in Unreal Engine | UE5
12:17
Ali Elzoheiry
Рет қаралды 130 М.
UE5 Understanding hard and soft references - Be a better game dev
19:58
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН