Clarification regarding soft references and casting?

I’ve been looking into using soft object and soft class references but I’m unsure as to exactly what’s happening and whether I’m using them incorrectly, misunderstanding their purpose, or misunderstanding the Size Map. The problem that I’m having is that I can’t access the data of a specific Actor or Class without casting to that Object/Class, and as soon as I place a “Cast To” node, the object is loaded into the Size Map.

Is the asset actually being loaded into memory when the game starts then, or is it only loaded into memory in the Editor’s Size Map? If it’s being loaded into memory even in-game, then how can I correctly utilize Soft References to utilize an object while still only loading it when necessary?

Here are some images which will hopefully help demonstrate my issue. When the object is placed as a soft reference, it’s not loaded into memory:
Referencing_1


But as soon as I place a Cast To node in order to use the object of that type, everything is loaded into memory:


This happens regardless of whether I’m using a soft object or soft class reference, and I can’t spawn an actor of class “BP_Enemy” without casting to BP_Enemy from the Resolve node.

In order to access properties of your casted object unreal has to load the whole class definition of BP_Enemy into memory. That is what the size map is showing you. To prevent that you can define an interface that is being implemented by BP_Enemy and use its interface methods on the loaded (uncasted) asset.

There are some nice YouTube videos that explain it much better then I do. Checkout https://youtu.be/U0RCO0id1kI by @Ari_Epic for example.

3 Likes

you can also use inheritance, so you could cast to actor class or a lightweight base enemy class

2 Likes

Thank you guys!

I think I’ll continue to explore the topic because I still don’t think I’m quite understanding the purpose of and process for using soft references, but it makes sense to use a lightweight base class for the time being and Interfaces where possible.

to give you an example of its purpose, say you have an itembaseactor and you have 1000 items in your game, each item has materials, sounds, meshes etc

now if you put all those hard references in a datatable, when you access that datatable for any item you load all 1000 items, if you put a soft reference in that database it will only load the base class and then you can load the actual item in code

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.