Are Soft References in Blueprints equivalent to Pointers in C++ ?

I am looking for something similar to pointers in C++ to use it in Blueprints.

Soft References look promosing but this tech article says that Soft References still reference / load the type of the object.

Do pointers in C++ do this too ? Are Soft References in Blueprints a serious alternative to C++ and the pointers ? ( memory, performance etc. )

C++ pointers are low-level memory addresses that can be used to directly reference and manipulate memory. Pointers can be used to efficiently allocate and deallocate memory dynamically, and they are also used to implement complex data structures like linked lists and trees.

Soft References in Blueprints, on the other hand, are a higher-level mechanism that allows you to reference assets and objects in your scene without maintaining a direct link to them. Soft References are designed to automatically handle object and asset garbage collection, which means that they do not need to be explicitly deleted when no longer needed.

In terms of memory and performance, Soft References are less efficient than pointers in C++, as they add an extra layer of abstraction that can affect performance. However, they can simplify the process of referencing assets and objects in your scene, and they can help to avoid common issues like memory leaks and dangling pointers that can occur when using pointers.

So, Soft References in Blueprints are useful for referencing assets and objects in your scene, but they are not a direct replacement for C++ pointers. Whether you should use Soft References or pointers in C++ will depend on your specific needs and the type of project you are working on.

4 Likes

Thank you very much @EliasWick!

I currently try to understand if the risk and the extra effort of C++ and pointers is worth it, so I’d like to know how big the difference in “quality” of the code / visual script is.
How would you rate the performance needs, memory usage and overall complexity ( e.g. risk and the extra effort ) of hard references, soft references and pointers relativ to each other in an average game project. Like a simple tier list…

The difference between references and pointers isn’t what is going to give you big speed gains when you switch to C++

Have you seen this?

1 Like

In Unreal Engine, a soft reference is a type of object reference that stores a reference to another object, but unlike a normal object reference, it doesn’t keep the target object alive. If the object is deleted, the soft reference becomes null. Soft references are useful for temporarily referencing objects without keeping them alive.

The difference from pointers is that a pointer is a low-level language construct that directly holds the memory address of an object, whereas a soft reference is a higher-level construct that can handle the complexities of reference management for you. Pointers must be manually managed to prevent memory leaks, whereas soft references are designed to automatically handle the cases where the referenced object is no longer in use.

Thank you @ClockworkOcean. I watched the video and it seems to indirectly answer the question.

Looks like in general it is not recommended to use C++ to reference assets like visual effects or meshes etc… -And this was basically my consideration to use pointers in C++ to get rid off the hard references to assets in Blueprints to save memory.
So for me the answer is that Soft References are the way to go, without any C++.
They reference the assets in an elegant, light weight and robust way, that doesn’t seem to be possible in ( pure ) C++. And the little benefits of additional C++ code seem irrelevant to me in an average game or multimedia project.

Well @Probezeit there are two kinds of Soft References:
Soft Class References just store a “link” to an asset ( and its type ) that is NOT automatically deleted after some time.
You need to load a Hard Class Reference to the asset first to use it. The loading is the huge difference to normal Hard Class References.

On the other hand you can store links to Hard Object References ( that were spawned ) in Soft Object References, like you can do it in Hard Object References, like most people do it.
And now: Yes… this Soft Object Reference will also be “null” / empty if the asset it is linking ( or “pointing” ) to is deleted by the garbade collector. This happens if there is no more Hard Object Reference to the asset.

-Really sad that the Blueprint Nativization was removed in Unreal 5…
But I am really excited to see how the Verse language will handle and hopefully further ( or again ) improve things…

2 Likes