good explanation and examples! So for what you are saying at 3:49 , it looks like your Character and PlayerController will be ALWAYS loaded in memory. so, hardreferencing those in any other blueprint should be "safe", or am I missing something?
this is amazing info great video if your struggling with memory issues or when your just starting and want to make sure your doing everything 100% correct from the get go. I have a question though I usually avoid casting to anything by using the "get actor of class" node as long as I know what actor it is directly im referencing for instance the player itself. my question is does this essentially work the same way as the soft reference ? Not loading into memory until called ? Thanks again your channel is an amazing resource on true object orientated clean code in UE5!
Thanks! Get actor of class does use hard class reference, so you have to be careful there. Also it might not be too performant, since you are going through all actors in your level, so if you have a lot of actors, it will take longer to find your player. If you are creating a single player game, you can use get player pawn, or if you are searching the owner of the component you can use get owner.
Quick question, if I have my PlayerCharacter already loaded in memory and I send a reference inside a BP (like a door or a key blueprint), will the PlayerCharacter be loaded twice in memory or only once since it was already loaded anyway? :O
Excellent video, I came looking for a better understanding of Soft Reference. in #5:24 the reason why the reference remained was due to the error that did not allow the BP to be compiled.
@@polysiens I'm having a difficulty that I couldn't resolve with Soft... I have a Blueprint Actor Component inside my Character and I needed to bind an event dispatcher that occurred on the character. The 'get Owner' doesn't catch the dispatcher having to do a 'Cast to Character' but then the Actor Component gets heavy, I tried everything with the soft and I couldn't. Here's a content idea for you and some help for me. :)
Hmm, there are few ways, but none of them are very good for this in blueprints. One way is for you to create a base class with all of the dispatch events. Then you can cast to that and all of the actors that need to use the events will have them. Another way would be having a custom event in the component that you call when the dispatch is triggered. Not sure if there are any other clean ways with dealing with that if you want to keep the component discponnected. @@GeneralNovais
@@polysiens What I've done so far, and it's working for me until I find something better. was to create a "custom Event" in the Game Instance and in the game instance that calls the event Dispatch, so in the BP that I want to bind event dispatch I do get game instance -> bind event dispatch and in the BP that I want to trigger the event dispatch I do get game instance -> Custom Event. it has worked. and I don't "overload" on memory any BP.
Another interesting point that came to mind is that the soft class approach making a 'cast to Actor' and not directly to BP_SpawnActor has a "complication" if your BP_SpawnActor has initialization variables ("exposed on spawn") is not possible use directly. Or am I wrong?
@@polysiens I overcame this difficulty by creating an Interface that has functions that will be implemented in the BP to be spawned and after spawning with a soft class I call these functions the Interface to populate the initialization variables. It turned out better than I expected and I managed to reduce the size of the animal. What I'm in doubt about is that BP that uses Data Table is "loading" along with practically all other BPs that also use Data Table. :/ I do not know why. For example, I have a BP that uses Data Table, when I look at the map size it is there DTable > Third Person Character >.... if I remove the use of DTable, this entire reference disappears. :/
Yea interfaces can be a workaround. If you have data table with hard references then it will load the class into the memory. You have to have soft references in the data table also.@@GeneralNovais
It would be pretty similiar to a normal use of soft references, you would just grab it from the DT row instead a variable in an object. I have few videos in works, but will put it on the list and might make it in the future. @@GeneralNovais 👍
Is there a way to reference a blueprint that is created by sequencer? I’m using OSC to drive a rig (not using control rig though, just setting relative offsets of meshes with float values) and in order to play back the animation in sequencer after it’s recorded with take recorder, I have to disable to OSC server. I can do this with a branch and it’s working great but I’m trying to access that variable only on the blueprint that’s created by sequencer and not the blueprint that’s in the level.
What is the purpose of soft references? because it will take the same disk size & memory size like the hard reference but after u tell it to do am i right?
Yes, with soft references you control when something is in the memory instead of having it there all the time and sometimes using it(or not even using it at all).
@@polysiens I like how u are trying to help others by replying Thanks for your assist! i have another question if u mind. (Noob question) if i have reference of actor inside a specific actor and the same reference of actor inside another actor is that mean the assists of that actor will be loaded in the memory twice? or only 1 what ever u do like the engine is smart enough to not load the same assists again or not? because i was thinking the amount of things that will be loaded in the memory while playing is huge!.
Thanks! The asset is loaded only once in the memory and you can have different instances of it created multiple times. Also if you have an actor that is referenced in multiple places, that actor will only be in 1 place in memory.@@MonderMurshed
I assume there is a way to unload them from memory afterward? Like say the object you spawn dies and fades away and it was the last one in the scene, what nodes are required to flush it out of the memory?
When object is removed from the level and has no more hard references, at some point the garbage collection will remove it from memory. To spawn or construct it again, you would need to use soft object/class reference to load it again from disc into memory.
@@polysiens Oh it's essentially automated? That's handy. I'm new to unreal so I'm more familiar with Unity and addressable system where you have to release it manually.
If I am not mistaken it's not loaded in memory but in disk. Hence on the top it says disk size. When I look at the standalone package the disk size use increases not the memory. am I wrong?
Also I heard soft references can be more prone to crashes, specially multiplayer when server relies on that path to not fail during loading time in case that specific memory is taken by something else prior to being assigned the reference or because of the delay.
Soft reference stores just the path into memory when object with it is loaded and then you can choose when you want to load the actual asset. Disk size in this context shows that if you load an object with a soft reference, you won't load the actual object and all of their dependencies, so your memory won't be burdened right away and you can choose when to load certain stuff.
There could possibly be a bit more issues if the developer is not careful, but you have different ways to test if the asset is loaded or not. There would be a balance between setting everything to be soft reference and setting everything to be hard reference. The balance would depend on the game. There are a lot of advantages to having control over what is loaded into memory, but it does come with a bit more effort needed to keep things stable.
@@polysiens I'd say a good example of using soft-references will probably be with player outfits, as you don't really want all of them loaded in memory when you're only able to use one at a time. Then when you go into the outfit select menu you can load them as the player scrolls through and unload them when they leave the menu or switch to a different outfit in the list.
I still don't understand how to use it, but at least I've understood what it is for. A shame that no one never talks about it, I've never seen a marketplace asset using soft object reference ...
The general idea is that whenever you use hard reference, the object has to be loaded into memory, but with soft references, you choose when. Yea, marketplace assets usually don't focus on memory optimization, just on content unfortunately.
@@polysiens Thank you, if I understand correctly it is principaly for assets? let's say I have get actor of class->cast to actor class-> promote as variable, this variable doesn't need to be soft ?
It can be for anything, assets are the primary use just because they usually take the most memory. Usually what happens is that you can reference an actor that references another actor that has some asset that takes a lot of memory, so even if you are not referencing the asset directly, the asset is still loaded into memory. Ex: Character->Gun Actor->Gun Mesh. Even though your character does not have a hard reference of the gun mesh, it will be loaded into memory because the character has hard reference to the gun and gun actor will load all of the hard references he has.
good explanation and examples! So for what you are saying at 3:49 , it looks like your Character and PlayerController will be ALWAYS loaded in memory. so, hardreferencing those in any other blueprint should be "safe", or am I missing something?
Yes, if you have classes that are always referenced in your game or level, hard referencing them in other blueprints is generally safe 👍
Wonderful video on the subject!
Thanks!
this is amazing info great video if your struggling with memory issues or when your just starting and want to make sure your doing everything 100% correct from the get go. I have a question though I usually avoid casting to anything by using the "get actor of class" node as long as I know what actor it is directly im referencing for instance the player itself. my question is does this essentially work the same way as the soft reference ? Not loading into memory until called ? Thanks again your channel is an amazing resource on true object orientated clean code in UE5!
Thanks!
Get actor of class does use hard class reference, so you have to be careful there. Also it might not be too performant, since you are going through all actors in your level, so if you have a lot of actors, it will take longer to find your player. If you are creating a single player game, you can use get player pawn, or if you are searching the owner of the component you can use get owner.
Quick question, if I have my PlayerCharacter already loaded in memory and I send a reference inside a BP (like a door or a key blueprint), will the PlayerCharacter be loaded twice in memory or only once since it was already loaded anyway? :O
He will be loaded only once 👍
Excellent video, I came looking for a better understanding of Soft Reference.
in #5:24 the reason why the reference remained was due to the error that did not allow the BP to be compiled.
Thanks!
Yea, that might be it, good catch. I think hard reference will still stay if you have it on any function as an input.
Thanks!
Yea, that might be it, good catch. I think hard reference will still stay if you have it on any function as an input.
@@polysiens I'm having a difficulty that I couldn't resolve with Soft... I have a Blueprint Actor Component inside my Character and I needed to bind an event dispatcher that occurred on the character. The 'get Owner' doesn't catch the dispatcher having to do a 'Cast to Character' but then the Actor Component gets heavy, I tried everything with the soft and I couldn't. Here's a content idea for you and some help for me. :)
Hmm, there are few ways, but none of them are very good for this in blueprints. One way is for you to create a base class with all of the dispatch events. Then you can cast to that and all of the actors that need to use the events will have them. Another way would be having a custom event in the component that you call when the dispatch is triggered. Not sure if there are any other clean ways with dealing with that if you want to keep the component discponnected. @@GeneralNovais
@@polysiens What I've done so far, and it's working for me until I find something better. was to create a "custom Event" in the Game Instance and in the game instance that calls the event Dispatch, so in the BP that I want to bind event dispatch I do get game instance -> bind event dispatch and in the BP that I want to trigger the event dispatch I do get game instance -> Custom Event. it has worked. and I don't "overload" on memory any BP.
next time keep the music low volume :D
great video thank you
learned alot
Really great video!
Thanks!
Another interesting point that came to mind is that the soft class approach making a 'cast to Actor' and not directly to BP_SpawnActor has a "complication" if your BP_SpawnActor has initialization variables ("exposed on spawn") is not possible use directly. Or am I wrong?
Yes that is one limitation that you would have to keep in mind. That is why I usually use soft references for assets more than for complex blueprints.
@@polysiens I overcame this difficulty by creating an Interface that has functions that will be implemented in the BP to be spawned and after spawning with a soft class I call these functions the Interface to populate the initialization variables. It turned out better than I expected and I managed to reduce the size of the animal. What I'm in doubt about is that BP that uses Data Table is "loading" along with practically all other BPs that also use Data Table. :/ I do not know why. For example, I have a BP that uses Data Table, when I look at the map size it is there DTable > Third Person Character >.... if I remove the use of DTable, this entire reference disappears. :/
Yea interfaces can be a workaround. If you have data table with hard references then it will load the class into the memory. You have to have soft references in the data table also.@@GeneralNovais
@@polysiens Can you make a video showing this use of DT with soft ref?
It would be pretty similiar to a normal use of soft references, you would just grab it from the DT row instead a variable in an object. I have few videos in works, but will put it on the list and might make it in the future. @@GeneralNovais 👍
Is there a way to reference a blueprint that is created by sequencer? I’m using OSC to drive a rig (not using control rig though, just setting relative offsets of meshes with float values) and in order to play back the animation in sequencer after it’s recorded with take recorder, I have to disable to OSC server. I can do this with a branch and it’s working great but I’m trying to access that variable only on the blueprint that’s created by sequencer and not the blueprint that’s in the level.
Hmm, not sure. You can check out Sequencer DIrector Blueprint and see if that helps.
I'll check that out, thank you!
Very good video! Thank you
What is the purpose of soft references?
because it will take the same disk size & memory size like the hard reference but after u tell it to do am i right?
Yes, with soft references you control when something is in the memory instead of having it there all the time and sometimes using it(or not even using it at all).
@@polysiens
I like how u are trying to help others by replying Thanks for your assist!
i have another question if u mind.
(Noob question) if i have reference of actor inside a specific actor and the same reference of actor inside another actor is that mean the assists of that actor will be loaded in the memory twice? or only 1 what ever u do like the engine is smart enough to not load the same assists again or not?
because i was thinking the amount of things that will be loaded in the memory while playing is huge!.
Thanks!
The asset is loaded only once in the memory and you can have different instances of it created multiple times. Also if you have an actor that is referenced in multiple places, that actor will only be in 1 place in memory.@@MonderMurshed
@polysiens U are a life saver mate!
thank u i was really worried about this point u have new sub!.
I assume there is a way to unload them from memory afterward?
Like say the object you spawn dies and fades away and it was the last one in the scene, what nodes are required to flush it out of the memory?
When object is removed from the level and has no more hard references, at some point the garbage collection will remove it from memory. To spawn or construct it again, you would need to use soft object/class reference to load it again from disc into memory.
@@polysiens Oh it's essentially automated? That's handy.
I'm new to unreal so I'm more familiar with Unity and addressable system where you have to release it manually.
Wow, nice, your content is live saver, you got subscribe from me! :D
If I am not mistaken it's not loaded in memory but in disk. Hence on the top it says disk size. When I look at the standalone package the disk size use increases not the memory. am I wrong?
if you create the variables, it then creates a reference for memory. And it takes less space in disk but more memory.
Also I heard soft references can be more prone to crashes, specially multiplayer when server relies on that path to not fail during loading time in case that specific memory is taken by something else prior to being assigned the reference or because of the delay.
Soft reference stores just the path into memory when object with it is loaded and then you can choose when you want to load the actual asset. Disk size in this context shows that if you load an object with a soft reference, you won't load the actual object and all of their dependencies, so your memory won't be burdened right away and you can choose when to load certain stuff.
There could possibly be a bit more issues if the developer is not careful, but you have different ways to test if the asset is loaded or not. There would be a balance between setting everything to be soft reference and setting everything to be hard reference. The balance would depend on the game. There are a lot of advantages to having control over what is loaded into memory, but it does come with a bit more effort needed to keep things stable.
@@polysiens I'd say a good example of using soft-references will probably be with player outfits, as you don't really want all of them loaded in memory when you're only able to use one at a time. Then when you go into the outfit select menu you can load them as the player scrolls through and unload them when they leave the menu or switch to a different outfit in the list.
I still don't understand how to use it, but at least I've understood what it is for. A shame that no one never talks about it, I've never seen a marketplace asset using soft object reference ...
The general idea is that whenever you use hard reference, the object has to be loaded into memory, but with soft references, you choose when.
Yea, marketplace assets usually don't focus on memory optimization, just on content unfortunately.
@@polysiens Thank you, if I understand correctly it is principaly for assets? let's say I have get actor of class->cast to actor class-> promote as variable, this variable doesn't need to be soft ?
It can be for anything, assets are the primary use just because they usually take the most memory. Usually what happens is that you can reference an actor that references another actor that has some asset that takes a lot of memory, so even if you are not referencing the asset directly, the asset is still loaded into memory. Ex: Character->Gun Actor->Gun Mesh. Even though your character does not have a hard reference of the gun mesh, it will be loaded into memory because the character has hard reference to the gun and gun actor will load all of the hard references he has.
@@polysiens I got it. But anyway when the asset is loaded, it takes the same space, it is just a way to load only necessary asset if I'm correct
@VirtualCore It is not hard, there is just no infos about it. And I wish I could buy assets