it seems to have to do with garbage collection and memory usage. its explained pretty well in the stackexchange post linked below.
Soft variable references…
- What are they?
- How are they used?
- WHY would I use them?
- Can someone give me a good example use?
Simple terms please!!! Thanks in advance!
- They are made to keep refrences to objects or assets that may not exist and referencing assets without loading them. Soft object variables also wont create hard references to blueprint. While normally object references would throw you errors, if you would delete asset and dont fix refrences that could damage the blueprint. In technical terms, they hold path to the object or asset, similar way as ini config does or data tables.
- Same as object reference practically, blueprint will auto cast to object refrence if you want to call function on asset or send it, when used asset will be automatically loaded. If object won’t exist the cast would give null, you can check validity beforehand too
- As side of refrencing assets that may not exist at runtime, many possibile reasons, one is to reference asset without loading it when it not really needed, can be used for optimization. You can actully (and i didn’t know that myself checked that just now) reference objects on the level, without it needed to be loaded. You can actually make soft reference and set actor on the level as default. Any reason you can think of when object may not need to be loaded and or asset may not exist at the time of the use
- I don’t use them much myself so i don’t have any, but i can explain what they do.
Can someone give me a good example
use?
I’ve been using soft references recently when building an inventory crafting system of sorts.
- I want to show an image of an item in the inventory without spawning the actual item.
- The user will browse a lot of items and I do not want to spawn anything until they’re happy with their selection.
- I want to show just the image in the user interface and maybe some variables that define it, stats and so on.
- Stats are easy, but the image - Texture2d is actually an object itself; an object that does not exist until its owner is instantiated.
My object class has soft referenced Texture2d that I just fetch from the class defaults and load that bit only instead:
Can someone give me a good example use?
Soft References are one of the way to reference objects in sublevels from the persistent level. Hard references don’t work, as you can’t be sure whether or not the sublevel is loaded.
There’s no quick answer to this but…
If reading is your preferred learning approach:
If video serves you better:
Thanks alot for sharing the links, I’ve already watched the stream but the article is far more interesting and clear