Unreal engine noob here so forgive me if I’m doing something completely wrong
So I’ve been learning more about blueprints in depth through youtube tutorials recently and I’ve discovered how you can use Soft references to optimize your game more over just casting everything, since casting leads to it being always loaded.
So my question is: How can I access the variables or parts of a specific blueprint with soft references / async loading?
In this image I have an overlap box, and if my player hits it, I wanna do specific things inside my character’s blueprint. Instead of directly casting: What I did was async load my player and check if both the classes are the same.
In the reference viewer you can see how it changed to red so it’s more optimized.
It works and I get the print string succesfully. However the problem comes down to actually accessing my character?
How can I go inside it without casting or doing it in an optimized manner? Casting is gonna have it always loaded and I’d rather try doing it in another way. Say I had a variable inside my character I wanted to change, how would I go about doing that?
If anyone could explain and let me know if this is even possible I’d appreciate it!
in the example you have you’re just doing a comparison so could compare to the say the parent class, eg. is it a character. or the player pawn itself. you could also use tags or interfaces.
to access variables directly you either need to cast using the exact class or a smaller parent class. or again use interfaces.
the simple answer is to use interfaces but in your specific example there is no reason not to cast as the firstpersoncharacter is likely always loaded anyway.
an example of proper use of soft references is if you had 10 characters and you dont want to load them all when the player will only use 1
I’ve just been seeing a bunch of videos on optimization so I was assuming I had to go about a process like this for everything.
My reference viewer is starting to get kinda big for my character, is there any rule of thumb or anything important I should know about scenarios to use soft references in?
I’m still new to learning them so I’ve been quite unsure.
my rule of thumb is dont overthink it haha,
on a small indie game you likely dont need soft references at all
but since it is good practice i’d say only worry about the heavy stuff, textures, sounds effects etc. the easy way to do this is have small empty parent classes that you use as hard references and child class that have all the effects.
when you spawn the heavier classes thats when you can use soft references but save it as its parent class if that makes sense.
no a soft reference is basically a path to the asset, thats why you cant access any class information off it until its loaded, pointers point to memory.
one other tip i should say about references is watch out for dependencies. (again dont stress about this too much)
this is where say your controller spawns a pawn, the pawn spawns a weapon, the weapon spawns an explosion/sound etc. now anytime you reference the controller it drags in everything down to the explosion.
yeah that’s where the reference viewer is handy right? I can take a look at it and make sure I’m not referencing anything too crazy that’s referencing it’s own set of items and just filling the memory up instantly the second my player character loads in.
Luckily my character doesn’t reference anything crazy besides just some input actions, widgets, and a few powerups