Тёмный

UE5 - Data Storage Using Object Class 

3 Prong Gaming
Подписаться 10 тыс.
Просмотров 8 тыс.
50% 1

In this video I go over how you can use an object class to store and retrieve data.
----------------------------------------------------------------------------------------
Thank you to everyone who continues to support me through the years. I am blessed to be a part of this community and I look forward to getting involved again.
Join the conversation. Be the community:
☛ / discord
Support the channel:
☛ www.buymeacoff...
☛ / 3pgaming
----------------------------------------------------------------------------------------
PC Specs:
☛ Processor: Ryzen 5950x
☛ MB: Gigabyte Aorus Master X570S
☛ Ram: 4x16gb Corsair Vengeance Pro
☛ GPU: EVGA FTW3 Ultra 3080
☛ AIO: Corsair iCue H150i RGB Pro
☛ Storage: 2x Samsung 980 Pro 2TB
----------------------------------------------------------------------------------------
★ RTS Playlist: • UE4 RTS Tutorial Series
----------------------------------------------------------------------------------------
Portions of the materials used are ®, (tm),(mr), and/or (mc) Epic Games, Inc., and/or copyrighted works of Epic Games, Inc., in the United States of America and elsewhere. All rights reserved, Epic Games, Inc. This material is not official and is not endorsed by Epic Games, Inc.

Опубликовано:

 

18 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@NeatWolf
@NeatWolf 8 месяцев назад
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 8 месяцев назад
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
@BoryslavF
@BoryslavF Год назад
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
@PlacetoPlay
@PlacetoPlay 6 месяцев назад
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 6 месяцев назад
You can replicate almost anything but I do not review multiplayer in my videos, sorry
@PlacetoPlay
@PlacetoPlay 6 месяцев назад
@@ShortBusTripeven this objects? because when i try this earlier it doesn't work(
@ShortBusTrip
@ShortBusTrip 6 месяцев назад
@@PlacetoPlay 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
@PlacetoPlay
@PlacetoPlay 6 месяцев назад
@@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!!!
@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!
@karthigamoorthy8701
@karthigamoorthy8701 Год назад
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 Год назад
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 6 месяцев назад
No, you would create an _array_ of instances of this class and manipulate them using an index in that array.
@ShortBusTrip
@ShortBusTrip 6 месяцев назад
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
@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.
@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
@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
Далее
The Right Way to Spawn Objects in Unreal Engine | UE5
18:03
Inheritance Tutorial (Parent Child) | Unreal Engine 5
34:51
У НАС ДОМА ЗАВЕЛАСЬ КРЫСА 🐀
01:00
Smart Data Storage -- UE5 Blueprints
14:50
Просмотров 4,3 тыс.
Unreal Engine - Casting and Interfaces Explained
21:31
Unreal Engine Data Assets EXPLAINED
11:23
Просмотров 8 тыс.
Unreal Engine #14 - Asset Manager
43:35
Просмотров 7 тыс.
UE5: Infinite Ocean on ANY Landscape (at ANY Height)
36:21