Thanks to you, I finally figured out how interfaces work and how to create them, as well as how they can help me optimize my project. I was really struggling with this, but now, thanks to you, I’ve got it all sorted. Once again, a huge thank you! :))
best way Ive found to do that is to have the interface return a soft reference then you can load that and have full access to every var and function on the BP without making the interface cluttered with a ton of gets and sets ... it can just have 1 function called ReturnSelfSoftRef :)
@@ryanjdev87hi, i know it's been 5months (lol) but can you explain your solution in a simplest/more visual way?🙏🏻 im a beginner and dont get it yet but already making a game, understand that it'll be heavy on memory and i believe with you trick i will not be doing this mistake👊🏻
This is hands down the best video you've made so far :) Super straight forward and simple explanation of a subject that a lot of people (including myself) completely miss with Blueprint programming. I'm shocked that casting is even an option now after seeing this. Love it!
Tip there is no point avoiding casts entirely, if something is constantly used or loaded (ie player character) cast away as it will not duplicate and waste memory.
@@MaxHorror Essentially as the only reason to avoid casting is to avoid hard references, which then wastes memory, but if something’s constantly in memory casting is fine but also look into blueprint interfaces and blueprint function libraries, as they do the same thing but are just a lot cleaner code.
@@jomesias If it is something that will always be loaded in memory such as gameInstance, Player character. But avoid doing this on things that are not persistent, such as an item from one level that is not in another level :)
You can also use tags as an alternative to casting or comparing to the class we need. Actor has tag, or get all actors of class with tag (this is more expensive though because it scans the Level Hierarchy. Another alternative is to check if it implements an interface
Can't believe I didn't know about Size Map until now... Thanks so much Matt! I have a grid-based game and one of the tiles was 200mb, now down to 68. There's easily 100+ of these in any level. This was also how I learned to CLEAN UP BLUEPRINTS AND MATERIALS because I did not realize unused things left in the graph are actually still being referenced. That makes total sense, given how blueprints are just code, but I did not realize it until now. I had at least 3 large textures being referenced despite them not even being used. Whoops!
From what I understand, each object references the player, but they won't actually load the player each time or load a separate copy. They are still just references. Player is always loaded anyway, so really won't be an issue. It will be an issue if they are somehow doing a cast of some other object that won't always be loaded. This would cause extra memory to be used.
another thing if your having memory problems is to look at the memory profiler and you can even build and launch the game using memory insights for further debugging. Another big tip is that I was using 16GB or ram for a long time while making my project everything ran fine untill I added alot of 4K textures in the game. I was using over 95% and UE5 would crash with out of memory errors all the time. If you ram is over 70% usage I would say double it (like I did from 16GB to 32GB etc) and ue5 will just be alot happier all the time not shifting Gigs of memory to compensate for your lack of memory. Also make sure to remember that what the editor is showing in the top right of ue5 if you have it enabled is the memory usage for the editor and the game. You have to build the game to see what it will use without the editor on top
Wow this really is a great way to save up memory. Thank you! I have a question: When I started my project I was new to unreal engine. Meanwhile I really do understand it pretty good. But back then, I used a "cast to 3rd person char" for every variable I wanted to reference. So when I wanted to reference to six variables, I used six "cast to" nodes. Nowadays I would only use one, or just use your method now. Do you have some tips on how to port the old "cast to" nodes to the new method? I mean, if I delete them, all my variables will get invalid. So I must place all the BPI interfaces and manually replace all the variables. Or is there any way to like "automatically replace" these "cast to" and their variables with the BPI method? Thanks and best
Hello Matt, does it not in certain situations make sense to have stuff already in memory? stuff that you are going to interact with i mean? and why is the player character using extra memory, it should be in memory at all time anyway? i dont really understand... i mean, we live in times where microstutter, stutterstruggle and so on is persistant everywhere.. so, did you ever compare a worst case szenario when running a game with more memory usage and with less? I mean, having more stuff in RAM or VRAM is not a bad thing, isnt it?
Edit: I'm not sure I understand anything anymore 😅 I have a character generation menu, where you can basically pick from an array of metahumans, but the data table that holds this list will always load ALL the materials etc.? Thanks! I finally understand WHY you should avoid casting. Everyone always says "you should avoid casting, it's harder on the performance, do this instead", I don't think I ever read or heard someone explain why that is and how much more ressources it takes.
What I've always been wondering is how bad the reference really is. Yes in this this case that would load the third person character into memory, but that's only a one time thing right ? So even if I have 10 of those pick-ups, only one third-person blueprint would be in memory with each having a reference to it ? And since it's the player character, the third-person bp would be in memory anyways no ? That would mean having a reference to it in all other BPs wouldn't use more memory ?
I recently stumbled on to something. A GPU with a lower amount of VRAM will have less editor VRAM usage than a GPU with a larger amount of VRAM. I was shocked and surprised when my 24GB RTX 3090 was getting out of video memory errors compared to another user with an AMD card with 16GB VRAM that had no trouble. Using an identical project, the 3090 had around 4-5 more GB usage, ruled out background apps as well. Then I repeated the test on a laptop mobile 3080 GPU with 16GB of VRAM and it also had lower VRAM usage than the 3090 in the same project. It's been suggested that the Unreal editor may be allocating extra VRAM based on the maximum amount of VRAM available. It's also possible that windows or even Nvidia drivers are a culprit. Either way, what's the point of having more VRAM if that extra VRAM is not going to be available? It's very easy to test and confirm this if you have multiple computers with different sized GPUs.
Maybe silly questions but does the scene== MEMORY see al these BP_Items as its instances=== taking only 111,3 Mb in memory or does it count X times when you have X such actors in the scene. I'm 99% sure it sees them as instances so takes only 111Mb in memory for this "kind" of object, just wanna be sure
Very cool video. I am wondering if the references increase the overall memory needed, if multiple object reference an asset. For instance, if 4 cubes reference the player character, is it 4x 100mb or is it only 100mb, because its the same reference. Also, since the player character is probably also in the scene, would removing the hard reference actually reduce the memory size, since its already in memory? I know its not the point of this video, but still curious about how (or if) UE handles deduplication.
It's 0 because the player character is probably always loaded anyways. You should be very wary of casting from the PC to other objects though because then they are kept in memory
Wow, this should be default way to do references don't know why other tutorials don't mention this. Can you make one for Lighting and Graphics, I swear even the basic ThirdPersonGame when exported uses 100% GPU for some reason
casting is the equivalent of calling the class itself and pointing to the object of that class. It is a pretty big misconception that casting is costly by today's standards. The problem is that if you hard reference everything and you cast to a previously unloaded class, it will load all references in it as well, making it "costly". But your player character, that is pretty much always loaded, doesn't cost a thing at all. Casting is basically like saying, "I want to get this object of this class, give me all associated information". Interface is basically "send a message of this interface to this object"; if it has the interface and a corresponding event, it does stuff; otherwise nothing happens. Very good for systems like damage, or messages. Delegates are like subscriptions. When actor A does and event, instead of it having to fetch all other actors and TELL them to do it, all actors spawn and are subscribed to that event. When it happens, they know!
You can cast to the player character as much as you want. It's always loaded anyways. Same with player controller, gamestate, level blueprint and game instance. Cast away there. Be wary of casting away from these though
You could do either but it doesn't matter. Since the game state or controllers are always loaded, casting doesn't add any more or less ram. You just make a call. To be honest, it is way easier to cast than to set up interfaces and events for every single variable.
Thanks to you, I finally figured out how interfaces work and how to create them, as well as how they can help me optimize my project. I was really struggling with this, but now, thanks to you, I’ve got it all sorted. Once again, a huge thank you! :))
That’s amazing to hear! I’m very happy I could help you out! :)
An important lesson. I hope you make more of optimization lessons
So it's a way of creating a soft reference as opposed to a hard reference. Really helpful!
best way Ive found to do that is to have the interface return a soft reference then you can load that and have full access to every var and function on the BP without making the interface cluttered with a ton of gets and sets ... it can just have 1 function called ReturnSelfSoftRef :)
Makes sense. I'll have to set it up to really understand it. Thanks!@@ryanjdev87
@@ryanjdev87hi, i know it's been 5months (lol) but can you explain your solution in a simplest/more visual way?🙏🏻 im a beginner and dont get it yet but already making a game, understand that it'll be heavy on memory and i believe with you trick i will not be doing this mistake👊🏻
@@mam9zyc Feed Chat Gpt or any AI with the text ryan said and the context you are in. AI will help you! I work the same way.
This is hands down the best video you've made so far :) Super straight forward and simple explanation of a subject that a lot of people (including myself) completely miss with Blueprint programming. I'm shocked that casting is even an option now after seeing this. Love it!
Thanks for the support! It’s always a pleasure to help :)
Would an in-depth tutorial be possible regarding optimization
Tip there is no point avoiding casts entirely, if something is constantly used or loaded (ie player character) cast away as it will not duplicate and waste memory.
So just go nuts with casting to your character?
@@MaxHorror Essentially as the only reason to avoid casting is to avoid hard references, which then wastes memory, but if something’s constantly in memory casting is fine but also look into blueprint interfaces and blueprint function libraries, as they do the same thing but are just a lot cleaner code.
Thank you @@wolffuschia
Cast once, on begin plat let’s say, and store it to a variable.
You just reduced your casts to 1! 💯
@@jomesias If it is something that will always be loaded in memory such as gameInstance, Player character. But avoid doing this on things that are not persistent, such as an item from one level that is not in another level :)
Very interesting and useful video. Always good to learn more about how to optimize. Thanks for teaching this.
You can also use tags as an alternative to casting or comparing to the class we need.
Actor has tag, or get all actors of class with tag (this is more expensive though because it scans the Level Hierarchy.
Another alternative is to check if it implements an interface
Can't believe I didn't know about Size Map until now...
Thanks so much Matt! I have a grid-based game and one of the tiles was 200mb, now down to 68. There's easily 100+ of these in any level. This was also how I learned to CLEAN UP BLUEPRINTS AND MATERIALS because I did not realize unused things left in the graph are actually still being referenced. That makes total sense, given how blueprints are just code, but I did not realize it until now. I had at least 3 large textures being referenced despite them not even being used. Whoops!
Great tutorial. More people should be aware of this.
Please keep up with these rare tutorials man!❤
A proper lifesaving tutorial, he shows proper way of doing things, I subbed ❤❤❤
Perfect video and a great first look into interfaces and optimisation.
really interesting topic u covered thanks mate keep doing great job.
Exactly what i needed, thank you
thank you, this is really helpful
From what I understand, each object references the player, but they won't actually load the player each time or load a separate copy. They are still just references. Player is always loaded anyway, so really won't be an issue. It will be an issue if they are somehow doing a cast of some other object that won't always be loaded. This would cause extra memory to be used.
another thing if your having memory problems is to look at the memory profiler and you can even build and launch the game using memory insights for further debugging. Another big tip is that I was using 16GB or ram for a long time while making my project everything ran fine untill I added alot of 4K textures in the game. I was using over 95% and UE5 would crash with out of memory errors all the time. If you ram is over 70% usage I would say double it (like I did from 16GB to 32GB etc) and ue5 will just be alot happier all the time not shifting Gigs of memory to compensate for your lack of memory. Also make sure to remember that what the editor is showing in the top right of ue5 if you have it enabled is the memory usage for the editor and the game. You have to build the game to see what it will use without the editor on top
finally a good explanation on why casting can be "bad"
Super helpful
I optimise my game by 0.5 GB down thank you!❤
I know that naughty dog hat limitations for their entire combat system to be under 5mb. 100mb for one item bluepeint is crazyyy
@@DadBod1818 TLOU1 was in a talk about their combat system on gdc i think
Wow this really is a great way to save up memory. Thank you!
I have a question:
When I started my project I was new to unreal engine. Meanwhile I really do understand it pretty good. But back then, I used a "cast to 3rd person char" for every variable I wanted to reference. So when I wanted to reference to six variables, I used six "cast to" nodes.
Nowadays I would only use one, or just use your method now.
Do you have some tips on how to port the old "cast to" nodes to the new method? I mean, if I delete them, all my variables will get invalid. So I must place all the BPI interfaces and manually replace all the variables. Or is there any way to like "automatically replace" these "cast to" and their variables with the BPI method?
Thanks and best
Hello Matt, does it not in certain situations make sense to have stuff already in memory? stuff that you are going to interact with i mean? and why is the player character using extra memory, it should be in memory at all time anyway? i dont really understand... i mean, we live in times where microstutter, stutterstruggle and so on is persistant everywhere.. so, did you ever compare a worst case szenario when running a game with more memory usage and with less? I mean, having more stuff in RAM or VRAM is not a bad thing, isnt it?
Oh my goodness., Thank you. I reduced memory use of my game by gigabytes in five minutes using this advice.
thanks, easily useful
Great video
Edit: I'm not sure I understand anything anymore 😅 I have a character generation menu, where you can basically pick from an array of metahumans, but the data table that holds this list will always load ALL the materials etc.?
Thanks! I finally understand WHY you should avoid casting. Everyone always says "you should avoid casting, it's harder on the performance, do this instead", I don't think I ever read or heard someone explain why that is and how much more ressources it takes.
You should use soft references in data tables.
What I've always been wondering is how bad the reference really is. Yes in this this case that would load the third person character into memory, but that's only a one time thing right ?
So even if I have 10 of those pick-ups, only one third-person blueprint would be in memory with each having a reference to it ? And since it's the player character, the third-person bp would be in memory anyways no ? That would mean having a reference to it in all other BPs wouldn't use more memory ?
I recently stumbled on to something. A GPU with a lower amount of VRAM will have less editor VRAM usage than a GPU with a larger amount of VRAM.
I was shocked and surprised when my 24GB RTX 3090 was getting out of video memory errors compared to another user with an AMD card with 16GB VRAM that had no trouble. Using an identical project, the 3090 had around 4-5 more GB usage, ruled out background apps as well. Then I repeated the test on a laptop mobile 3080 GPU with 16GB of VRAM and it also had lower VRAM usage than the 3090 in the same project.
It's been suggested that the Unreal editor may be allocating extra VRAM based on the maximum amount of VRAM available. It's also possible that windows or even Nvidia drivers are a culprit. Either way, what's the point of having more VRAM if that extra VRAM is not going to be available?
It's very easy to test and confirm this if you have multiple computers with different sized GPUs.
For example I want to communicate with two blueprint and none of them playerCharacter. What should I connect target part of interface node
What about using Common Function Library to cast to the character and then calling that function. Does it work thr same as using the Interface?
Maybe silly questions but does the scene== MEMORY see al these BP_Items as its instances=== taking only 111,3 Mb in memory or does it count X times when you have X such actors in the scene. I'm 99% sure it sees them as instances so takes only 111Mb in memory for this "kind" of object, just wanna be sure
Very cool video. I am wondering if the references increase the overall memory needed, if multiple object reference an asset. For instance, if 4 cubes reference the player character, is it 4x 100mb or is it only 100mb, because its the same reference. Also, since the player character is probably also in the scene, would removing the hard reference actually reduce the memory size, since its already in memory? I know its not the point of this video, but still curious about how (or if) UE handles deduplication.
It's 0 because the player character is probably always loaded anyways. You should be very wary of casting from the PC to other objects though because then they are kept in memory
Amazing
Great optimisation from 109 mb to 1.7 mb.
Can this solve the crash about kernel32/malloc block...??
When I make things, Like Materials, I tend to make them 1K and not the 4K materials, I guess this helps, when taken from Blender to a game engine.
Wow, this should be default way to do references don't know why other tutorials don't mention this. Can you make one for Lighting and Graphics, I swear even the basic ThirdPersonGame when exported uses 100% GPU for some reason
Thx
super
When should you cast? Why does it exist
casting is the equivalent of calling the class itself and pointing to the object of that class. It is a pretty big misconception that casting is costly by today's standards.
The problem is that if you hard reference everything and you cast to a previously unloaded class, it will load all references in it as well, making it "costly". But your player character, that is pretty much always loaded, doesn't cost a thing at all.
Casting is basically like saying, "I want to get this object of this class, give me all associated information".
Interface is basically "send a message of this interface to this object"; if it has the interface and a corresponding event, it does stuff; otherwise nothing happens. Very good for systems like damage, or messages.
Delegates are like subscriptions. When actor A does and event, instead of it having to fetch all other actors and TELL them to do it, all actors spawn and are subscribed to that event. When it happens, they know!
@@philzan3627 Thanks a lot! you put that together really well
You can cast to the player character as much as you want. It's always loaded anyways. Same with player controller, gamestate, level blueprint and game instance. Cast away there. Be wary of casting away from these though
would you still go with interfaces over casting when it comes to communicate with GameState/PlayerState/Controllers etc... ?
You could do either but it doesn't matter. Since the game state or controllers are always loaded, casting doesn't add any more or less ram. You just make a call. To be honest, it is way easier to cast than to set up interfaces and events for every single variable.
*Breathes in* lets sort this snakes wedding
I right clicked one of my blueprints and it said 4GBs.... I store all my casts in variables so hopefully its fine :/
If it works on the platform you have planned, don't worry too much, mine weighs 7GB and works well on low-resource pcs
it works for ue4?
It does yes!
@@MattAspland ok