again this is why I like your videos. I know there are already some other videos explaining soft ref but in general I found in your content "tip and trick" for someone who already have time in unreal engine and it's useful info for having later. Thank you so much!!
@thegamedevcave10 ай бұрын
i'm glad to hear that! :D
@t3hpwninat0r6 ай бұрын
after you do the load thing for the soft object referenced variable, it will stay in memory as long as that variable still has that value. later on you can set the variable to some empty value and the space in memory for the class will be marked as "ready for garbage collection" and the engine will know that when it needs to free up some memory (garbage collection), that space in memory is a good candidate.
@randomancyАй бұрын
How do you set to an empty value? I'm trying to get better about memory leaks.
@t3hpwninat0rАй бұрын
@@randomancy option 1: don't waste time optimising things that don't need optimising when you could be spending your time on actually useful tasks like finishing the game. option 2: in blueprints, use the node for setting a new value but don't give the input pin a value. option 3: go learn c++ because i can't teach you in a youtube comment :P
@randomancyАй бұрын
@@t3hpwninat0r true, but I’m doing both for a game competition, and using it as an opportunity to learn best practices instead of just throwing *something together haha So if it means learning when to use Async, or pure/impure functions, or thread safe, or soft references, and I can just use them from the start, seems worth it 🙂
@randomancyАй бұрын
@ also I can’t dev all the time, so sometimes I’m reading or watching KZbin to apply the concepts later when I’m back at the PC 😁
@YoutubeAccountMan8 ай бұрын
It's tricky to know when to use this. It seems like a problem with this is that your game has to wait for soft object references to load while playing the game. Fine for something incredibly small, but you don't want your game to lag every time you have to play an animation. Also, soft object references are NOT freed up when your ability or whatever ends. In C++ you have to delete the pointer, but you can't do that in BP so it stays loaded until the game is closed. Soft references are one way you get memory leaks in BP iirc, so be careful.
@thegamedevcave8 ай бұрын
Assets referenced in an object will be removed from memory whenever that object is destroyed. Unreal's garbage collection takes care of any Uobject that is loaded but not referened anymore. As for lag, thats why you load these things async, its being loaded on a seperate thread so your game doesnt stutter, you just need to make sure that the code on your game thread doesnt try to use that asset before it gets fully loaded.
@joeypouladi10 ай бұрын
Wow I had no idea about this and the potential impact it has on performance. Thank you, very informative👍
@thegamedevcave10 ай бұрын
Glad to have helped out!!
@occupationalhazardАй бұрын
This is the best explanation of Soft Object References that I have seen. Really simple when you get down to it. Are there any reasons to not use them?
@thegamedevcaveАй бұрын
they will complicate your code a fair bit because you won't know if the object you're talking to is loaded or not. in simple contexts that's not a real issue but especially if multiple other objects are running functions on something that relies of a soft ref, that can be a bit of a headache. so if it's not going to be an issue, like the object is fairly small, or should always be ready to be used no matter what you wouldn't want to use them. things like animations are a good example, and i kind of made a mistake showing soft refs of in thsi video with animations, because those you probably want to have as hard refs usually. the mesh is already always loaded as it is, and animations are pretty lightweight but when you want to run an animation you want to run it NOW. not next frame, or even a few frames from now (which would also change depending on the hardware). so for animations it almost never makes sense to use soft refs Where soft refs become most important is if you want to be able to reference a kind of object that comes with a lot of it's own hard refs. only loading in all those refs when it's actually being used can end up saving you a lot of memory. a closely related subject would be casting (since the main issue with a cast is also creating a hard ref) which i have a video on too : kzbin.info/www/bejne/o2PZhHiNZqlkoq8
@BiZkiDD25 ай бұрын
How did you connect the nodes at 6:36 ? Looks like magic!
@thegamedevcave5 ай бұрын
that's just an edit i'm afraid xd
@BiZkiDD25 ай бұрын
@@thegamedevcave 🤣 oh man, and I just wasted half an hour researching "automatic node connection". Anyways, thanks for a great video!
@akumadj756910 ай бұрын
easy way around loading multiply assets is to use gameplay tags/string/enums to idetifiy which phase of attack or which attack needs to be loaded then use a select to run the branch you need. Allowing you to know chain 100 async load nodes but rather just call the ones you need.
@thegamedevcave10 ай бұрын
I wouldn’t say that’s easy, if you want to load one of a few possible assets you can just pass in a soft obj ref variable instead
@TheSoloDIYerКүн бұрын
Can you please make a video walking us through the *why* you structured each of the links show at @2:20 that way. For instance, why is there a BP_SA1 and BP_SA2 referencing the same things? And what does the BP_SA3 do, and why is it separate? A lot of videos go into micro-specifics, but none go over the macro-design patterns as a whole, which I think is equally as important (maybe even more so). Essentially, give us a rundown as to why each of those connections were created, what they do, and why they are separated into standalone files (or why they aren't).
@thegamedevcaveКүн бұрын
BP SA1 through 6 are children of the swordattack base. sword attack base is the actual class with all the code in it for the gameplay ability. it deals with playing animation, timings of things, sending and recieving gameplay events, particle and sound spawning. but many of those things, like the animation and the particles are simply variables that get populated in the child classes. so the reason they all reference the same things is because their parent class likelt is the thing actually refencing those other assets (through a cast to the thirdperson character blueprint). BP_SA3 being diffrent is likely just because i hadn't populated it with values at this point i have to assume. BA_SA1/2/3 etc function almost more like assets than proper classes in that regard. Right this moment I dont remember exactly how things were set up in that situation exactly but it's fair to say that at this stage in my project i was very much trying to get things to work first, and then optimize later so there isn't a lot of deep thought put into refences and such in that regard in this situation. But as a whole, that was (and still largely is) the structure of how these BP_SA blueprints work for me. This is the kind of thing that i will often ramble about when people ask about it in livestreams as that's a format that works better for more large scope things compared to videos that tend to require a somewhat tighter focus. Downside being is that its hidden inside 3 hour long streams.. so maybe i'll experiment with cutting those out and uploading them as highlited segments? That might be interesting
@TheSoloDIYerКүн бұрын
@thegamedevcave thank you very much for explaining all of that. I'm just getting started watching your content, so I'll probably run across it eventually.
@vivegamespk8 ай бұрын
today i really got actual concept of soft reference. Thanks
@HoduAphrodite8 ай бұрын
This was so much more comprehensive than similar content I've seen regarding soft references
@thegamedevcave8 ай бұрын
Glad it was helpful!
@AlexTLOU3 ай бұрын
Thanks! Learned something new now
@TheModExperiment8 ай бұрын
1:00 OMFG!!! I click here and see then my idle animation have +100(!)mb unlike of other animation of walking and other things (+\- 10mb) Thank you for showing this tool :3
@chamussoide3 ай бұрын
Ehi There! Great Video. I have a question though: It's super clear what Hard and Soft Object references work to me, however I'm a bit confused about the Hard/Soft Class References. As you (and many others) said, an hard reference means that the referenced element is stored in memory. But what does it mean for a class? I'm my mind, as a c++ programmer, when we allocate memory we are actually creating an instance of a certain class, so what exactly is a class reference in blueprint and how it can be transposed in the "programming world"? The only thing that makes sense to me is that a class reference in memory is an instance of the interested class, but with all default values and it is used to create instances of that class (a.k.a. actors), probably with the usage of the copy constructor. I?m looking forward to the answer! Many thanks in advance!
@thegamedevcave3 ай бұрын
A class reference is a reference to the static class instead of to an object. So it works the same way as the object hard and soft reference for memory usage but instead you use it for things like spawning actors or constructing objects.
@chamussoide3 ай бұрын
@@thegamedevcave awesome, It stars to be clearer to me, but a lot of fog disappeared ❤️
@owencoopersfx10 ай бұрын
Thanks. How do you get the reference viewer to show the whole reference chain instead of just one reference layer at a time? Didn’t know that was a feature.
@thegamedevcave10 ай бұрын
top left there's a little settings menu that allows you to set how deep on both sides it should show the connections
@vrai_9 ай бұрын
the annoying thing is async node doesn't return the exact class
@crossmr4 ай бұрын
Use interfaces and you never need the class.
@dreambadger10 ай бұрын
I keep all my montages in a map with enum selections. I could probably convert them to soft refs and have the selected montage feed into a single async node, which is in my function called Montage Picker. Then montage picker can have a pin to plug into the anim montage player. I'll test it out.
@thegamedevcave10 ай бұрын
always good to try and to things like that if you can! but frankly, for the most part this kind of headache isn't worth the effort for animations because they're so small in size anyway, it's more relevant when you have references to assets like meshes and materials or whole other types of actors that you try to use soft references when you can. The animations in this video were mostly for demonstration purposes :)
@dreambadger10 ай бұрын
@@thegamedevcaveThanks, yeah I did wonder. Maybe I'm trying to optimise the wrong thing. Cheers.
@everBlossom98003 ай бұрын
You said that to unload assets you'd need to learn to c++. Could you recommend somewhere where I can learn this? Currently managing audio and animation for a project, and managing when something need to be loaded and unloaded is really important, but I'm struggling to find learning resources
@thegamedevcave3 ай бұрын
any loaded assets will unload together with the thing that loaded them. so if you have an object that loads a class , once said object is destroyed, so will the loaded class (or asset) this is usually enough. C++ has a few more functions to unload soft object pointers without needing to destroy the object that loaded it in, which can be useful, although a pretty niche scenario. It might be easier to just create a custom object that can handle the loading, then when you destroy that object, the loaded assets will also be taken care off instead of managing it through C++ Like i suggest in this video, especially if you dont have familiarity with C++ to begin with. Nonetheless, i have a whole playlist on my channel that can help you get started with C++, and from that point, you'd have to find the functionality through unreal docs (or more likely through people asking about it on the unreal forum), because i dont fully remember what files it requires and the names of the functions. In most scenarios i'd say you want to manage your assets inside the actors that'll be using them though, at which point unreal's own garbage collection will just take care of everything for you like i mentioned :)
@everBlossom98003 ай бұрын
@@thegamedevcave Thanks for the fast reply on an old video I'll check out the playlist once I'm more curious about c++, but the fact that destroying an actor unloads its related assets is incredibly useful to know! One quick thing though: Do you know if unloading a level stream will also unload it's associated assets? Maybe it's obvious but I would like to be sure
@thegamedevcave3 ай бұрын
@@everBlossom9800 yes, the only time you have to worry about unloading something manually is if you load in a soft object reference like in this video in an actor that doesn’t get destroyed. Any other scenario, if some asset loads in another asset, it will also unload that 2nd assetbonce the first gets removed. That goes for blueprints, meshes, materials, textures and even levels. In 99% of cases Unreal takes care of all that for you. Only very rarely will it be needed to explicitly unload an asset (which is why it’s limited to c++ functionality because you don’t really need it)
@MichaelGaskin10 ай бұрын
Great video! Could you do an async load when a specific weapon is activated? Rather than when the player uses that ability? So, when the sword is your primary weapon, any montages needed for the sword weapon are pre-loaded before the actual ability is fired by the player.
@thegamedevcave10 ай бұрын
For sure could! it's a bit of a puzzle on a case by case bases which assets you make hard and which you make soft references. in this case, instead of loading every animation through a soft reference like I do in the video, what would make more sense is to have the abilities themselves be soft references on the weapon that load on when the weapon it equipped. then the animations inside the abilities can still be hard references which will get loaded in and out with the weapon as a whole since the abilities would be soft references!
@MichaelGaskin10 ай бұрын
PERFECT! Your approach makes much more sense than mine (montages). The tools are there with UE5, its really about nailing the logic of using them. Thanks again! @@thegamedevcave
@sarfraz853310 ай бұрын
Unloading process? How to free memory when animation done playing.
@thegamedevcave10 ай бұрын
there isn't a way in blueprint to unload manually. when the object that loaded in the asset is destroyed it'll free up the memory again and otherwise unreal's garbage collection will also try it's best to unload once it think you are no longer using those assets. Manually unloading is a c++ only thing and for the most part not something you usually need to worry about.
@sarfraz853310 ай бұрын
@@thegamedevcave I am playing different animation montage again and again around 100 Anim 100 times using soft reference and load asset method called , how to profile this to check memory stack and not causing issue?
@thegamedevcave10 ай бұрын
just load them in when they are relevant, they should just get taken care off
@ryanjdev8710 ай бұрын
U can use collect garbage node to force collection in blueprints It states it should only be done when a hang is acceptable.
@BaseRealityVR10 ай бұрын
Can you not just use the Async Object out pin instead of hooking up the variable Directly, Or am I mistaken?
@thegamedevcave10 ай бұрын
you can! but the reason I dont do that is because it makes a lot of ugly confusing looking lines all over your blueprint. and you can't promote it to a variable because then you are making a hard reference again which makes the whole soft obejct reference and async loading obsolete. so just loading it and then using the soft reference variable is the cleanest way to do things and shouldn't give any issues if you make sure that by the time you use the reference it's actually loaded it (which also goes for if you were to use the output value from the async load node)
@BaseRealityVR10 ай бұрын
Good Point@@thegamedevcave
@TheFlyingEpergne7 ай бұрын
so would you say if you know an actor is definitely going to be loaded in a level anyway its ok to have it as a hard reference? e.g i have multiple instances of a BP_House that is present pretty much throughout my entire game - that sort of thing would be ok to hard reference as it will always be loaded?
@thegamedevcave7 ай бұрын
actually am planning to release a video about this very thing soon, in short : yes if you know something will be loaded anyway, there's no real harm in making a hard reference
@stereocodes10 ай бұрын
would sequence be better for async asset loading? also is there no such thing as async all or all settled in unreal/cpp? group all async calls into a single async listener that waits for all calls to finish?
@thegamedevcave10 ай бұрын
the sequence node doesn't really do anything other than allow you to more neatly organize your nodes really. So if anything, for just putting all your Asynch loads in the first output of the sequence will help you get organized but the sequence node won't wait until those async tasks finish to move on (that's the whole point of an async task after all, you start it up and it completes in the background while the rest of your code keeps running) As far as loading multiple assets, i believe c++ has some way to do that which has a callback for when all assets in an array have finished loading but I haven't much looked into that as i've never really ran into needing to load in more than a handfull of soft references at a time.
@haxan47868 ай бұрын
comment for the algorithm! I was looking at the soft ref today, tried it and the compiler crashed, I shrugged and moved on. Now I know I have some optimizations I need to do -.-' I appreciate the priority list at the end there, actors and static meshes with textures.
@Siphonife10 ай бұрын
I understand streaming and why its useful but in 99% of scenarios I struggle find good reason for where and when its "OK" to have to wait for an object. If its not time sensitive then its cosmetic and can async load. If its not cosmetic then I need that object now to effect the game and async loads are going to delay the gameplay making a laggy mess. Lemme know what you think if you see this. What are good ways to load async and bad ways to load async.
@thegamedevcave10 ай бұрын
it's a matter of choosing the most efficient points to turn into soft objects. you could turn all your asset references soft but that then ends up with having to manually load in a LOT of assets (like in this video). Instead, if we take my example in this video, what would be a better way to do it is to make the gameplay abilty itself a soft reference, that way it, and all the hard references (which includes meshes, particles and material) in it get loaded in when I want. so when the ability becomes possible to use, i async load it, while all the abilities that aren't possible to use at any given time won't be loaded, but i'll still have references to them. For another random exmaple. say you'remaking a pokemon game. You can have a soft reference to your pokemon class so you have a simple variable to acces it through on the player (or player controller more likely) but you only load that in when the actual pokemon is spawned into the world
@dougwarner596 ай бұрын
If an object exists in memory and you perform a "successful" cast (hard cast) it will have no ill effects because the object is already loaded into memory. that makes sense, but the part that confuses me is why is it bad to have a Cast just laying around, you could have as many cast as you want and there will be no negative side effects because it is already loaded in memory...unless each cast actually creates a copy of the object it is casting to in memory. Each time you cast you have to create memory big enough to hold the object. Or maybe we are talking about two different types of memory: RAM and ROM(Disc) memory. maybe a Hard Ref will place an object in RAM even if you might not want or need it there yet resulting valuable recourses being unnecessarily used. I am still not sure; could you explain Hard and Soft reference as the relate to RAM and Disc memory?
@thegamedevcave6 ай бұрын
The issue is that hard references will ALWAYS keep the asset they’re referencing in memory, even if no object that uses them exists. So if you have a blueprint that has a hard reference to another blueprint that only appears in certain situations (like a specific level, only a handful of times in the game), it will now always be around in memory regardless of an object of that type actually exists. If you’re making a small game, that’s probably fine but this issue scales up pretty quickly… before you know it you’ve hard referenced so many things in so many different blueprints, you now have half the assets in your game loaded at all times, making your game use dozens of GB of ram.
@edgardsimon9836 ай бұрын
i think that when u cast it update the current value of ur class too so yes the class is in memory already but with the previous value
@thegamedevcave6 ай бұрын
@@edgardsimon983 the class itself doesn’t get updated. The actual objects of a class have their own values but a class itself is just a set of default (or static/shared) values. Casting loads those default values into memory, even if no objects of that class exist.
@edgardsimon9836 ай бұрын
@@thegamedevcave ok but it actualy update the object value or whatever, it update something right ? cause i m not sure how it work
@thegamedevcave6 ай бұрын
@@edgardsimon983 no, casting doesn't do anything to update any actual values. it takes in a reference and checks if the object you're referencing is also of the type you're acting to (so actor as input and it checks if that specific actor is a character). In order to do that, this blueprint now needs to know what a character is in order to do that check and afterwards, be able to access the information like variables or functions that exists on a character. so, it makes a hard reference to the character class. With c++ classes, that usually isn't an issue but when you cast to a blueprint class, that blueprint also has a lot of hard references usually to things like static meshes, which have references to materials and textures. Meaning that the casting to that blueprint loads ALL that into memory, just to be aware of what this class is, even if it isn't being used. This doesn't have anything to do with any values being updated in memory, that's just what happens when you change values on an object, and isn't really a problem in any way. The issue with casting comes in when , in order to be able to do a cast, you're loading blueprints and assets into memory like this.
@BlackskyRadio-x9s8 ай бұрын
omg you need to use interfaces to stop all those hard references. lol
@thegamedevcave8 ай бұрын
I got a video all about casting coming soon, why and when it is bad but also when it is fine to do.
@efekanssc67165 ай бұрын
It's very unnecessary and bothersome.
@thegamedevcave5 ай бұрын
For small scale projects it’s not something to worry about. If you have lots of blueprint and lots of assets, this does become an issue
@efekanssc67165 ай бұрын
@@thegamedevcave yeah if you making gta or something this is problem…
@efekanssc67165 ай бұрын
@@thegamedevcave I shared your channel in UnrealEngineTurkiye forum. Your channel is important.