Blueprint interface hard reference

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.

RefThroughInteractInterface

The easiest way to avoid hard refs, especially if you’re using interfaces, is to make the type of the variable ‘actor’ :slight_smile:

To answer your question, this

image

would create a hard ref in the blueprint it is in.

1 Like

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.

1 Like

If you make an actor you can’t access their data and you have to end up making a cast anyway.
This is where interfaces really become relevant.

Ok, so instead of getting the player ref itself, I just get the variable I want to use and that will not create a hardref to the player?

Yes, if you want to take its “speed” for example, create a function in the interface that returns the speed.

Ok, that makes sense. Guess Im gonna need a lot more interface functions! :slight_smile: Thank you!:slight_smile:

The point is, the actor you’re sending the message to, deals with the situation. You don’t access another actor’s variables :slight_smile:

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!:slight_smile:

1 Like

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 :slight_smile:

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… :slight_smile: ( what I mean is, you’re realizing this )

Yeah, seems like the common practise on youtube etc. is using object references. Thanks for the tip!:slight_smile:

1 Like

There’s a lot of stuff on youtube that people should be shot for… :smiley:

2 Likes

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

1 Like

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 :smiley:

1 Like

If you use a save game, make sure you don’t put any variables of non-generic types in there. So only int, float …

I had the nightmare looping reference tree from hell at one point… :sunglasses:

1 Like

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 !:slight_smile:

1 Like