Interface targets and get actor of class dilema?!

Hello everyone,

So Iv been applyingfrom everything i have read to have a good mix of interfaces and casting where appropriate.

Why can I only access interfaces using actors as get actor of class? (which I believe is a downgrade on performance due to going through the actors in level please correct me otherwise)

I have tried self and many other forms of targets to no avail and would really appreciate someone explaining to me how to make this more performative.

Thanks UE Sensi’s

1 Like

If you use ‘get actor of class’ then you’ve cancelled any advantage of using interfaces.

You only need an actor reference to talk to it with an interface.

Can you give me a usage example maybe?

A classic example of interfaces is interaction with objects. In that case, you’ll be getting the reference either from a line trace or overlap. Very often needing to know references up front doesn’t happen.

1 Like

So my problem only happens when using any blueprint actors to commuinicate.

For instance I have a spotlight that changes in a BP_Floodlight (Already placed in level) on button press from a WB.

I think in general. i kinda need a comprehensive breakdown of actor to actor interfacing.

with widget am i correct i just need create widget as the target?

:pray:

Communicating between widgets and stuff in the map is a bit more fiddly, because you can’t give the widget a reference beforehand.

One good route, is to create the widget either from the light, or an actor in the level that does know about the light. Then you can either pass a reference to the light into the widget, or a reference to yourself ( the widget creator ) and the widget can talk back.

Generally speaking, communicating between actors with interfaces is just that. ActorA passes an interface call to ActorB. They never know what kind of actor the other is.

Ok, soo in theory should i just be able to create a random actor variable and pass that as a target in my interface message?

I just finished moving a ton of logic out my level blueprint and using interfaces, I just need to find a more performative option than get actor of class haha!

thank you

1 Like

Yes, actor reference.

The moment you have a ‘MyBlueprint’ reference, it’s game over … :slight_smile:

Interfaces are no more performant than casting. The problem with casting is, once your project gains size, it will be riddled with cyclic references and you won’t be able to load anything in memory without half the project coming with it :smiley:

1 Like

Yeh, thats my understanding so far haha! :slight_smile:

Currently the unspaghetting is going well and i feel like this is the last gem to crack (Definetly Not)!

So i have some understanding from what you say but here are my examples of where I’m still struggling.

I have a character and an actor I’m trying to comunicate with. I have a character which blueprint in which I have an interface event.

BP NPC was from get actor of class which i want to remove!!

and I added a random character variable which im certain isnt what you mean XD

How does BP_NPC appear in the world? Is it spawned?

One method you can use instead of get actor of class, is get actors with tag.

Then at least what you get back is an array of actors, not blueprint types :slight_smile:

It is indeed spawned :slight_smile:

oh thats smart ill try that!

1 Like

There are sometimes when tags just can’t be avoided. I don’t know enough about your situation to say.

I had to use tags recently, as the actors that I wanted talking to each other were in different streamed levels :slight_smile:

1 Like

What is talking to the NPC?

What is the downside to tags? I use them for comparing component overlaps :sweat_smile:

As for what is i talking to the NPC hmm, would the reference viewer help?

It was worse believe it or not XD

1 Like

There’s no downside to tags, unless

  1. You have a ridiculous number of them ( >100? )

  2. You’re checking them on tick

With the NPC, I mean what is trying to make the interface call on it?

1 Like

I feel like at this point tick is the enemy haha!

oh so i added the interface to BP_NPC (character) and created event from the interface.

then in my BP_Gameover (Actor) Im calling out with the message node to the same interface.

Sorry if I made this vague or confusing, I’m not shall we say logic minded :sweat_smile:

Maybe this helps?

1 Like

Ok, so when the game over BP is ready, it can get the NPC with the tag and send it the message?

I tried with the get all actors with tag but nothing. could it be because the BP_gameover is already in the level so when it sends the message on begin play the BP_NPC isn’t spawned yet? but with a tag i thought that wouldnt matter.

1 Like

Watch out, there are more than one sort of tags on actors. You need this one

image

Not the component tag, above…

It can’t be game over on begin play?.. :slight_smile:

1 Like

Daaaaamn your my hero XD

So i had set a tag but I had done it on the component tag! durr.

Thank you so much :pray: :pray: :pray:

Yeh i dont know hwy i typed that the logic is tied to a begin overlap trigger event haha.

again man, cant thank you enough!

1 Like

Cool :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.