Does 'Resolving' a Soft Class Reference to 'Get Class Defaults' Create a Hard Reference?

As the titles suggests… if I take a soft class reference and ‘resolve’ it, in order to Get Class Defaults, does that create a hard reference or is this a memory safe technique? Thanks!

SoftToHard

A soft class reference is just a path, it can be used without loading a class into memory. Once you load (“resolve”) it you will load the entire class into memory.

3 Likes

Thank you, that’s helpful!

However, I’m still a bit confused because I just created an empty BP with a soft class reference variable and then found that it’s loading gigabytes of other assets into memory, which I thought a soft reference was exactly NOT supposed to do?

Am I misunderstanding something?

I never used this SizeMap tool, can’t say if this is the requirement if everything is loaded or if it is the actual currently used memory. It’s a bit high! Soft pointers / references do not load the entire class into memory. In BP the purple pins are hard class references which you should avoid. You can’t always avoid loading things into memory, you will load the attached ActorComponents, parent class etc at all times.

2 Likes

Size map shows either the size of disk or memory reference chains (similar to the Reference Viewer) and is supposed to be the tool to use when cleaning up reference dependencies. It’s helped me reduce memory load in my project tremendously and hasn’t lied to me, yet.

Everything I’ve read says ‘soft references aren’t loaded into memory until you specifically load them’ but what I’m seeing in the Size Map says otherwise. Confused.

1 Like

You could try the profiler tools to monitor memory:

Or hook into a standalone process of the game and see if it matches expectations?

1 Like

The hard reference to class W_Parent comes from the variable itself regardless of whether it is set to None, W_Parent or some subclass of W_Parent. The effects/benefit of the soft class reference comes into play when you actually assign some subclass of W_Parent since it prevents creating a hard reference to that class (BP_ClassC_ChildOfB in the example below). You may be able to change the type of the soft class reference to whatever is the base of W_Parent.

7 Likes

A-ha! I think you might have just cracked it wide open for me! Starting to make sense… I need to experiment with a few things, thank you!

One thing to keep in mind is the difference between resolve and actually loading the class.

2 Likes

Hi
I just recently learned about soft vs hard object/class references.
I found this article tremendously helpful in demystifying the principle of soft vs hard object references:
https://medium.com/advanced-blueprint-scripting-in-unreal-engine/object-references-in-blueprints-4c0df7f4dc1d

6 Likes

Indeed, very helpful article. He touches on one of the things that had me so confused…

“Beware though, the type is still loaded when using soft references, so if the type is BP_Weapon , it’s still going to be loaded with all its dependencies; therefore, it’s best if you use a C++ base class for variable types (you can still have a BP base class inherited from the C++ one), or a minimalist BP parent class.”

I think it’s time for me to learn C++.

2 Likes

Yup, Knowledge and incorporation of C++ will eventually become inevitable at some point :-/

Once you get good at c++ you can work faster than in BP and manage / update thousands of lines of code with a few clicks where BP would just roll over and fart requiring you to take a whole week to update BP.

Hey, that’s a great article, much appreciate it!

1 Like