Blueprint Interface to player controller Ue5-0

Im still new to unreal . Just a quick question on interfaces

I create an interface called getEnemy as I want to share the location of the actor in a number of places

I set the value of the interface GetEnemy in an pawn class as a message …

however when I try get the GetEnemy interface event inside “player controller” things seem to be invalid

image

Any Idea why this is happening or what I should be doing differently . All help is appreciated =)

I thought maybe the event tick had something to do with it, or the fact I’m not setting any variables to consume those interfaces . Not sure yet if delegates can be used in this way ? Or how to use casting inside of the player controller Blueprint…

The “then execution wire” from EventGetEnemy is not hooked up.

edit:
all you need on the controller is plug the isValid directly into the EventGetEnemy. You are already calling the function every frame from somewhere else.

2 Likes

a test you can do to help illustrate what is happening is to set an input key to call the interface funtion.

Then on each actor, implement the function and have a print string that reads the actors name.

Then you can see that when one actor calls the interface function, all actors that implement the function will do so for each time that it is called.

1 Like

Ill definitely try and do that I think that setting things on the event tick has something to do with it

Event Tick was the issue as when I run the steps in key press Interface is set and can be called …

1 Like

Your blueprint doesn’t have an execution pin from the “event get enemy” event handler.

If you want to CALL an event, you should not use the “implement an event” (red header) nodes, you should use the “call an event/interface” (blue header) nodes.

The value of the Enemy Object blue line is undefined in the graph above. In fact, this is a common enough mistake that I’m surprised the Blueprint compiler doesn’t just tell you it’s wrong when you try to run it.

If you want to store a particular enemy value when some particular event is called on you, then put that into a variable on the blueprint instance. Then read that variable when you need to retrieve the value. But, in general, every red-heading node (event handler) should have execution pins coming out of it; they are like functions being called ON YOU that you need to handle.

1 Like

Affectively Aside from the mentions above about linking the Execution pins this is what I was doing wrong

when calling the interface event (blue call ) my target was set to self so it was trying to run the event on the same BP

what fixed it was telling Target node to use the BP that invoked the event . Well I suppose I understand it now . . . Graph below

1 Like