I found a video called "Learn why you should NEVER use Casting in Unreal Engine" (How true is this ?)

So i found this video:

Which shows when using a “cast to” node on an almost empty actor BP It turns it’s memory size from a few hundered i think it was 800kb to around 200mb (it depends how much the target cast to bp is - If it is 5gb it will then turn the memory usage of the almost empty BP to 5gb as well). And that happens even if you only have the “Cast to node” in the BP and not even connected to anything…

So my question is - would it be worth to start and redo all my actor bp’s and try to avoid cast to nodes from now on at all cost ? And where would it be a “good” example to use it if at all ?

you could cast to a base class.i guess you should have a base class,where has no a skeletal mesh,Niagara,audio component,etc…
the size is almost coming from those textures,meshes…as long as your base class doesn’t have those,your free to cast.

2 Likes

Nice, i do have a base enemy class which don’t have a character mesh. I will see if i can improve further on this ty!

1 Like

right click on the BP in content drawer →size map.you can actually see how big it is.

1 Like

Yeah i see that’s in the video too. For some reason my enemy bp is 6gb and 5gb memory. There are no nodes on the event graph. The whole thing is pretty much empty. This size map shows me that it loads some textures from other player characters that i have. But now i am wondering how or where are they comming in this enemy base bp. The bp itself has only a few variables but no direct variable reference to those characters what the “size map” shows me. So not sure where this connection to the characters exactly comes from.

the cast to node has a return pin.


it’s like “auto” create a variable for you,if the target BP is huge then the BP use casting becomes huge.
actually any function returns a object variable will automatically create that object variable in the blueprint that calls the function.
that said,even if you didnt promote it to a variable,it’s in your BP anyways.
so check your base class’s variable type.make sure all variables are base class type,and doesn’t have a default value.keep them empty

1 Like

When you need a lot of casts (not to base classes) you sometimes just want to split up functionality into new classes or components, as that can often reduce casts count. Casting to the engine classes is still very common and there is nothing wrong with it. When using interfaces (as a best practice for decoupling) you are going to be casting as well.

Youtube videos are 99.9% clickbait. It’s expected to see a large increase in memory when a class you are loading into memory holds hard references to other classes / assets. Say a blueprint has a property / node referencing a class / texture / sound / level and so on through a HARD reference, they will be loaded into memory immediately (and recursively) when that class is loaded into memory. This is why people use soft references, which are nothing but paths that can be loaded on demand.

@catz111 that would be shocking. I think it’s loading something recursively through a property / component / etc that looks innocent but isn’t. Like a datatable reference holding hard pointers to other things like textures.

All about Soft and Weak pointers | Tutorial

The real problem of blueprint CastTo - #2 by Roy_Wierer.Seda145

Blueprint interface VS ActorComponent, The Good And The Bad

Die to Survive - Railshooter - #240 by Roy_Wierer.Seda145

1 Like