how to get reference to other actor with interfaces

The interfaces contain functions declarations which can be seen as a contract of interaction for objects implementing them.

Simple said, you have to tell “run this method on this (instanced) actor (blueprint)” by given the target where the interface is implemented and the method to be executed on.

Depending of the thing you want to achieve you have to keep a reference of the actor by referencing them in your blueprint or thorugh interactions like collisions or linetracing where you get the reference of the object your interact with, which can be used to call the implemented interface function on it.

this is the first time I’m using blueprint interfaces so it’s really confusing. so far I’ve been able to get a reference to my character with an interface function but this message call always requires some kind of target which I don’t know how to get for regular actors.

The whole point of interface calls, is that you can send a message to ANY kind of actor, whether it implements the interface or not.

So, naturally, the first thing you need, is a reference to the actor.

The two main ways of doing this are by direct reference in the level:

or ( if you are dynamically placing actors ), by getting the reference at runtime:

As t1n1n says, there are many other ways. Line traces being a typical example for first person games:

What if i want to get access to a blueprint that’s not going to be interacted in any way. is it possible to use interfaces for such scenario?

i want to get access

You always need a reference. What communication method to use depends on the circumstances. You know how you’re going to select actors, the editor does not. You know which actor, the editor does not.

If you only have 1 → Get Actor of Class and you’re done. It’s lazy AF but hey, if it works…

What if i want to get access to a
blueprint that’s not going to be
interacted in any way

You can create a hard reference. You’d need to disclose more details. What is the scenario?

Let’s just say there’s fuse box in my game that has a boolean called poweron and there’s another actor that will use this boolean to determine if a door should open or not. These actor are static and won’t be interacting with each other, what’s the best way for these actors to interact with each other?

Are they both in the Level Blueprint?


If they are:

  • create a variable of Door type in the Fuse actor:

  • select the Fuse in the Level and assign any door you want to it:


Calling PowerTheFuse opens that door.

  • another way is to make the Fuse and the Door be the same actor.
  • if they must be separate actors, the Fuse can have a Child Actor Component hosting a Door actor

These 2 methods would work well, too. What to choose depends on the scope / modularity / level design / convenience or the way you personally like to organise it all.

Oftentimes, choosing something that just sits neatly in your head triumphs over something fancy.

Thanks, there’s another actor which is spawned at beginplay so its not available in the editor. I had to use get actor of class to get access to that actor, but it says its slow operation and not recommended to use. Is there a better way of doing this.

Actually never mind i figured it out after thinking about it for a bit xd.

there’s another actor which is spawned
at beginplay

  • are we still talking about doors and fuses?
  • which blueprint is this actor spawned by?
  • who does this actor need to talk to?
  • or who needs to know about this actor?
  • where is that other actor that needs knowing about the dynamically spawned another actor
  • who talks to whom here?

The above is exactly how the editor feels when you do not provide a reference :wink:


I had to use get actor of class to get
access to that actor, but it says its
slow operation and not recommended to
use.

It’s fine if you’re not spamming it using on Tick (every frame) or in a giant loop. And if there’s only one.

Is there a better way of doing this.

Most likely, but you need to know the details to set it up. See the bullet points.

1 Like