Hi! I’m at a turning point in my project, and preparing to scale. I’ve tried to read up on the subject, but never really found a clear answer. What I am wondering is the best practises regarding interfaces. I am trying to avoid hard references, and i’m wondering if these examples create hard references.
Are hard references only created when stored as a variable inside a BP ? Is the output pin of a node considered a variable and therefor a hardref?
In my example picutures its one interface having the ref built into the interaction event, and the other one with no input on the interact, but an interface on the player getting the ref.
Alright, thanks! I guess that’s what people mean when they want you to use interface instead of casts. What is the best way to access the functions and variables of a specific BP using an “actor” as variable then? Seems a bit unpractical.
Yes, now you have the reference to your player just as if you had made a normal cast.
What you have to do with interfaces is call functions of your “Player ref”, either to send data or to collect it
But even if you make a soft reference everywhere, that object will still have to exist in memory during runtime, for example the player character is the first thing that is loaded into memory during gameplay, so it doesn’t really matter.
Soft references during runtime are fine when you have weapons, clothing, or widgets that aren’t always used continuously.
Another thing is during the work time in the editor, since the soft references prevent the entire game from loading when you open a blueprint o widget, (you open a inocent simple widget y all game is loades in memory) but that is more problematic for giant games with thousands of assets.
Thanks, that helps a lot. I have the habit of getting the reference of the actor itself to use its variables, but I guess I just need to find a way to access and use the variables directly instead if I’m reading this right. Thanks!
Just to be sure, this is the way I want to be using interfaces: Either get the variable directly and change it, or get the variable needed whenever trough some other event like overlap etc? And this is safe regarding hardrefs?
Maybe make it a bit more abstract, or like a struct so I can reuse the same interface for many variable types? Sorry for being so dense, Im just trying to wrap my head around this
It’s bad programming to reach into another actor to read or write variables. That might also be why you’re having problems with the concepts you’re working on now… ( what I mean is, you’re realizing this )
Overlap and interfaces are complementary
For example a door only opens a character has life above 80
With overlap you wait for the player to enter, them, instead of making a cast to see life, you use an interface to tell you life
With this event you could avoid multiple hard references of the overlapping object (it could be the player or an npc, or a stone) in the door blueprint.
BTW, I am a big fan of casting
Ok, thanks. Yeah, Im a fan of casting too, just gotta know when to use it. Right now im just trying to make it so not all BPs I have are linked to the player or gamemode. My ref tree is looking pretty scary atm
hehe, maybe I have. Thats confidential. Will do a good cleanup later today. Im making a small game, so I dont think it will be that impactful, but I would rather try do it the right way and get used to a more optimized workflow . Thanks for all the tips !