How can I access one blueprint's variables from another using Interfaces?

I’m really scratching my head with this. I used to make a lot of use of CastTo node and I want to get good practices. I’ve seen that Interfaces are the great solution and so far I’m happy with it, but of all the tutorials I’ve seen, they only show how to communicate blueprints with execution nodes.

What if I just want to get some variable value in another Blueprint? like it was done in Casting. Let me put an example:

I want to acces this enum in this other Blueprint.

I’ve created an Interface, assigned in both blueprints. The function only has an output pin with the enum.

I call it in the Widget BP, like this.

I set up a debug in the player’s BeginPlay

Doesn’t work.
5

How is this done? I would like to get some help as this is just an example, but there’re many variable get/set throught the blueprints and I would like to do it right!

I hope I understand your problem correctly, I’m pretty new to blueprints as well so if I get it wrong, my apologies.

I think this: " assigned in both blueprints" is where you might have gone wrong?

Interfaces aren’t like “bridges” that connect things. They are more like “classes” but they don’t have their own implementation.

So if you have BP A and BP B

and A wants to get something from B without knowing the exact class of B you can create a interface called “C”
A still needs to find a reference to B somehow. Maybe by colliding with it, searching for nearby actors or stuff like that. And then when you have the reference you can then assume it’s of interface “C” and use it as if it was.

I hope that helps a bit. I don’t want to explain to much in case I misunderstood you.

think of it like this:

Bob sees a person in the distance. He doesn’t know who it is. He writes a note on a paper airplane that says, “if you can read english, tell me your name”

he throws the plane and waits

the plane comes back and it says, “my name is jill.”

he does this again with another person, this time he gets no response. Apparently that person did not speak english.

So make an interface called “english speakers interface” and give it a function called “Whats your name?” This function should return a string.

Put two blueprint actors in the level. When you press key 1, do a “get actors with interface” and on the actor that gets returned, send the message “whats your name”.

In the blueprint actors who will listen for this message, implement the interface and into the return, type whatever their name should be.

If you get that working, that is everything you need to know to make interfaces work. Youtube tutorials make it seem like rocket science for some reason.

Also, don’t use interfaces just because you think it is better. It might have no use for you and just complicated workflow. Use interface when you need a one to many communication style where each of the many might handle the communication in a unique way. If it is one to many but the response is always the same, use actor components instead.

The issue with casting is that it has to load the class that is being casted to. It is doubtful as a beginner that you are achieving total decoupling anyway, so the effort with interfaces is probably wasted to that effect. And it is also doubtful that you’re going to hit a problem because of hard referencing, unless you were making a game that is way outside your scope, in which case you have much bigger problems anyway.

That’s not to say don’t study more and practice, just don’t waste time getting carried away trying to optimize things for problems you haven’t hit.

1 Like