Master Unreal Engine: Understanding Hard and Soft References
Вставка
- Опубліковано 19 чер 2024
- In this video, we'll be exploring the concept of hard and soft references in Unreal Engine. We'll be looking at how loading times can be improved by using hard references, and how memory usage can be reduced by using soft references.
If you're new to Unreal Engine or are looking to improve your game performance, this video is for you! By the end of this video, you'll have a better understanding of how hard and soft references work and be able to apply this knowledge to your own projects.
--
Links:
docs.unrealengine.com/4.26/en...
www.quodsoler.com/blog/unders...
dev.epicgames.com/community/l...
---
00:00 Whats the difference?
00:15 Example
01:01 Why this matters
02:00 Recommendations
02:25 Converting Hard to Soft pointer
05:49 Soft References in C++
09:44 Casts = References
12:24 Wrapping it up - Навчання та стиль
Trying something a little different, instead of a disembodied voice talking I wanted to have something on screen that was a bit more interesting to watch than whatever my mouse was pointing at. This was an experiment so let me know if it's working or not, if it's distracting / getting in the way from what I'm talking about let me know 😶
I like seeing your beautiful face
@@chasesommer 😅 thank you!
I have been about to pull my hair out trying to wrap my mind around this, I have probably watched close to 30 different videos attempting to explain this concept. Yours is the one that finally made me get it. Thank you.
That’s fantastic, thank you!
Great video. I love the fact that you show both blueprints and C++. Hope you continue making more!:)
Thanks, will do!
Thank you for this video this was extremly helpful since you also showed in C++!
Glad it was helpful!
Just saying Thanks for these kinds of videos, definitely things I wasn't really thinking about as I started dabbling in unreal engine again so always good to know and expand my knowledge!
Glad I can help! The engine is pretty huge but if you break it down into manageable chunks it's pretty awesome. Best of luck with your projects!
Earned a sub. Really very well explained, thanks a lot!
Awesome, thank you!
I'm just starting out and so far all the info I've coming into contact with suggest going straight to BP Interfaces rather that Casting so thank to folks like yourself for continuing the convo
Interfaces are a great way to keep things decoupled, good luck with your projects!
This is great, I had changed some skeletal meshes I wanted to load to a soft reference but they weren't loading, the async load node was exactly what I needed. Thank you!
Glad it could help!
Great video Dan, I've recommended it to my team 😊
Awesome, thank you!
your video is greatest i've seen a couple of them and i've learned so much. Expecting for your gameplay ability series~
Glad you like them!
Briliant! Thank you so much for this particular video. After reading 5 pages long articles full of water with as much sense as "games made with Unreal Engine use RAM", it makes me uneasy, that the concept of hard/soft references technically could be explained in one sentence lol I've recommended this video to all my fellow UE devs just in case hehe
Glad it was helpful!
A few spots that are not correct. Objects loaded through soft references won't stay in memory forever. If there is no hard reference pointing to that object, Garbage collection will step in and delete that object. That's why you don't see soft references get unloaded in source code.
Loading assets synchronously is not always bad. That's where the loading screen comes in. Lyra uses it extensively to load in crucial assets for the shooter core.
Heya, thanks for the comment,
If you stash the handle from the streaming manager, you have to manually release it for the objects the then be GCd, that’s what I was getting at. If you store off hard references to the objects and don’t stash the handle, they will be GCd the moment the hard reference is removed.
Sometimes you might want to preload a bunch of things but not necessarily keep them referenced directly, for example having a bunch of frequently loaded / unloaded equipment on a character. Preloading and stashing the handles allows for faster loading during gameplay.
Sync loading assets isn’t always bad, but if you can asynchronously load you don’t block the game thread for an undetermined amount of time, allowing you to give the players some feedback on what’s happening. Of course if there is a static loading screen you may want to just sync load, but if it’s animating on the game thread (via UMG, which I think is -only- game thread) then you will have it freeze until the load is done.
I was trying to get my head around using triggers in my VR project and I saw the notes that said casting is taxing. This video explained neatly how to do it right. Thank god I found this before I implemented too many features! Keep making videos about UE, you are great!
Glad it was helpful!
On the bright side, if you're already hard referencing the cast is near free xD
This video was amazing, thank you mate
Glad you enjoyed it!
Very clear explanation. Gonna use this video every time I need to pitch the necessity of the soft refs to designers :D
Glad it was helpful!
Great explainer, thank you!
Thanks!
Great info, thanks!
Glad it was helpful!
C++ eh?! That's gonna make me subscribe!! For some reason every Windows IDE I use works for a while then tells me all my code failed. But I'll get back to learning C++ one day.
Good video, but you should check your audio levels. I had to crank my volume to like 85% just to be able to hear you. My average volume sits at 6% if that gives you an idea.
Thanks for the feedback! I'll give normalising the levels a shot for the next video, I've been using headphones to review before hand so far, so that's probably the cause of it!
@@DanGoodayleUnreal Yeah doesn't change the quality of the video in anyway, but having to scale the sound so high makes notification sounds from like 'Discord' mildly fear inducing haha.
@@Whiskeysim hah I totally get it! Honestly each video I'm trying to change something to improve things gradually over time, I'll give the audio more of a look on the next one's and see how people react to it.
Thanks for your time letting me know, it really helps me figure out how to do all this 🫡
Merci beaucoup !
Great video and examples
Thank you!
wow, nice, thanks
You are most welcome
Can you please explain why (@4:38 +/-) you connected input of conversion pin to the "Montage to play" output and not to the Async Loader's "Complete" output? To my understanding, since the loader is async loader you would simply "fire" conversion pin too early, no?
good stuff
Thank you
Hey Dan thanks a lot for the tutorial. I have a little question thou. When I async load a soft class reference, do I not need to get the handle and unload/cancel it? Also what will happen if I async load a soft class reference in a struct?
Thank you!
but i have 2 questions.
1 - Can the same actor or class be loaded in the memory more than once? because if it does i must study more about these things.
2- if i did everything in hard reference it means all my stuff will be loaded in the startup of the game (everything?)
Thanks again for the video and i will be grateful to see your answers!.
1) No, the actor class defaults object will only be loaded into memory once. At that point any soft references to that object will then point to that.
2) yes in theory if you had a single object referencing every asset you could. You can also inadvertently load more than you want if you aren’t careful with hard references (loading a UI element which has a hard ref to a character BP for instance would load that BP too)
Thanks for the video. Im new and trying to learn all this stuff. My main character BP is like 400mb. Im trying to make sure nothing else references it to avoid them going from a 10mb BP to 410mb BP. But as soon as I connect them to a BPI, they are already 410mb. Maybe its the way im doing it, I have to play around with it more, but can you still make a hard reference with BPI? Maybe thats what im doing..
What’s showing in the reference viewer for the asset?
Can i use soft references to prevent the "Accessed None Trying To Read Property" Error messages? I have certain blueprints that, just for a moment, do that, then the asset loads and works properly.
Soft references wouldn’t load the object implicitly, you have to manually load it.
So if you wanted to use a function on it they would throw an error because it wouldn’t be loaded until you (or something else hard referencing it) loads the object first.
So, for example, when I spawn in AI characters I would use hard refrences? What is a must use case for hard refs?
Let’s say you have 100 different AI character types.
You would create some sort of data asset to manage them, you then use soft references to all of them.
Now to load that data asset you don’t then need to load all 100 AI characters (if they were hard refs you would have to). You could then take 5 of the characters and load their soft references into memory, then spawn those characters.
Does that make sense?
so, if i have a master Item blueprint (lets calle it BP_Item), parent of all items in the game. This BP_Item executes a "Get Data table Row" at some point, so it takes a DataTable as a hard reference, therefore loading the whole datatable into memory. Now let's say I have 20 items (children of the BP_Item class), does it means that the DataTable is being loaded 20 times in memory, using 20x memory usage? Or... if the DataTable is loaded for the first item to spawn, then the remaining 19 items will use that reference in already loaded in memory (no duplication)?
It'd only be loaded into memory once
@@DanGoodayleUnreal thanks for you answer!
Hi Dan. I´ve notived something strange. I´ve hooked a soft reference variable (anim montage) to a blueprint interface. In the bp that receives the interface message, I dont have to load the montage into memory, I can just pass it into the play montage node. Where does the anim montage get loaded?
So the blueprint interface requires a hard ref and you are pass in a soft ref?
If you try and do that it'll do a cast from soft to hard ref (in blueprint it'll look like a light blue dot changing to a darker blue dot).
If the asset has been loaded previously (and is still loaded) it'll resolve to the correct asset, however if it hasn't been loaded it'll return a nullptr. This can lead to odd behavior in cooked builds, as you may load the asset without knowing in the editor (you can load an asset in the editor just by double clicking it), but in a cooked build that asset may not be loaded.
@@DanGoodayleUnreal Hi. Thanks for the reply. No, I passed a soft ref in the interface. In my player bp I defined the soft variable "deathanimmonatge" (and entered the anim montage) and hooked it up to a interface function (soft ref) . My gameplay abilty uses the interface to pick up the montage. But I can just hook up the interface node in my ability bp to the play montage node and the anim play without having to load the asset. I haven´t opened the montage in the editor, so I don´t know why I´m am not getting a nullpt :-/ . very odd..
Could you grab some screenshots and post them here? Feel free to retract whatever you'd like, but it'll be helpful to debug things - and for anyone curious reading the comments :)
@@unreal_metronomus678 Cook the game in development mode and log whether the soft ref is valid when you aren't expecting it to be. The editor is super unreliable when it comes to debugging stuff held in memory. If it is valid and it shouldn't be, there's a 100% chance the asset is being hard-referenced elsewhere, which you can use the reference viewer to check.
@@GlassesAndCoffeeMugs Yes, after restarting the computer for a couple of times, I I got an error message that the asset wasn’t loaded ( correct behaviour) . Hmm, yes, you are right about the editor being unreliable sometimes .. anyway, thanks for your reply.
Something else i'm trying to tackle before scaling is circular dependencies
Forward declare what you can, interfaces help too
🥰
🫡
I do not have this damn async node, Unreal 5.3 I have in no blueprints been able to call this async node. What in the heck am I supposed to do.
Which async node are you after? I think that was on the version before (can’t check right now I’m travelling)
your audio volume needs to come way up
You aren’t the first person to say that! I’ve been trying new settings in later videos so hopefully that’s fixed. Hope the video itself was okay