Interface Calls

I was struggling to get an interface to set a variable on another blueprint but i was able to “solve” the issue by putting the function call on Event Tick which makes some sense as its a variable that will change constantly (Its an Enum for Player Turn). That being said Is this the correct way to go about this or is this “lazy”. i feel like im missing something as im using interfaces everywhere and ive yet to use one of the red custom events i see in every tutorial.

Addendum: The red custome event thing may be because im using interfaces purely instead of casting to pass variables and not to “Interact” with anything…

Addendum to the Addendum: I just accomplished the exact same thing using an event dispatcher with an input and no interface whatsoever so i dont even understand life anymore…

1 Like

Let’s say I have 2 blueprints. BPa and BPb. I’m in BPa and I want to set a variable in BPb.

Then my interface looks like this

image

In BPa

image

In BPb ( it implements the interface )

image

The one massively important thing to notice here, is that ‘actor reference’ is just that, an actor reference. It is not of type BPb reference.

Yes, at runtime, we do point it at BPb, but is of not of type BPb. If it is, you might as well not use an interface :slight_smile:

The variable i am trying to set is in GameMode and the place im trying to change it from is GameState. My custom versions but essentially the same. The point of all this was to eliminate some tech debt from gratuitous casting. i guess im not sure when to use which method for accomplishing what i want.

It will work for that, exactly the same way. And it does avoid the need for casting.

Screenshot 2023-05-04 164411

This is currently how all my interfaces look. they are working but i have no red event and when i try to create one it wont compile because it says a function with that name already exists on the BP which it does but even clearing the function doesnt seem to remove it from the BP it just seems to be a part of it now since its implementing the interface…

Screenshot 2023-05-04 164438

with something like this or the reverse inside the function on the target BP

Screenshot 2023-05-04 165453

I had this project basically complete but i had most of the core code on the playercontroller BP and a million casts so i restarted it to attempt to put everything in the right BP and eliminate casting so even though its working im more concerned with it being right since that was really the whole point of starting over.

If it takes params, but doesn’t return anything, you get a red event

image

But if you make a function ( ie, it returns something ), you can’t have a red event

image

because it’s a function.

If at some point you decide you no longer want it to be a function ( it doesn’t return a value )

You can convert it

image

image

1 Like

The events and functions are made for you

image

If you try and create the nodes inside the BP that implements the interface, you’ll just get calls to the interface. That’s why this

image

has a yellow pin.

1 Like

Thank you so much… That answered my question and some i hadnt asked yet.

1 Like