Interface calls in Macros

I made a macro to make interface calls simpler. It acts like a cast node without being so expensive. I want to be able to call it anywhere, so I placed it in a macro library with Object as the parent. I noticed that it says error under the interface call. It hasn’t caused any issues yet, and works fine in every blueprint I’ve used it in. Why does it think there’s an error?

A while ago, I believe I tried something similar. I don’t remember the specifics of it, but I recall that I edited the macro once, and that basically broke every instance of the macro. Even restoring it wouldn’t help.

What does the error say when you mouse over it?

It went away when I refreshed the nodes, but today when I started up Unreal I found four errors like this one:

:no_entry_sign: /Game/GUI/BP_HUD : Failed import for EdGraph /Game/Libraries/MAC_Standard.MAC_Standard:GetConeCharacter Referenced by export K2Node_MacroInstance /Game/GUI/BP_HUD.BP_HUD:EventGraph.K2Node_MacroInstance_1

Have you tried putting this in a function library instead?

I’ll give it a shot

The function version works in blueprints like the HUD, but not in things like Notify States.

Do you know if it’s the call to the interface that’s breaking the macro, or is it the fact that it’s parented to object? Maybe it’s not realistic to try and create something like this that works everywhere?

I added some validation checks, and for now it seems to not be returning any failures on startup. But I fear it could return at any time lol.

1 Like

incidentally, since you’re returning hard references anyway i doubt this is even more efficient than a cast

2 Likes

How come? That’s the whole point of making these, so if they’re not any more efficient, that’s not good lol. What should I do instead?

Why not just implement the interface that returns the needed elements.
If the object has the interface it will work, it it’s missing the interface it will be ignored.

The point of interfaces is decoupling.

If you need any tests then you could check the validity of an important object passed in the interface return value.

1 Like

So if I’m understanding you and Auran13 correctly, because I’m retrieving the entire blueprint, that’s just as inefficient as casting?

Pretty much. It’s over-engineering. Also make sure you take into account which elements that are returned are singletons.

GameState => it lives on the server, client’s don’t have one, you can return the server gameState only. At that point it’s a singleton so no need to grab it though a custom function, just use the “Get Game State” node.

And if you have to call a bp implantation function of you own gamestate bp version then add an interface to it and call the interface on the generic gamestate => it will work

No casting or extra logic needed.

2 Likes

Awesome. That clears up a lot for me. Thanks!

yeah ive heard mixed reviews on whats actually faster between interfaces and casts, that said when you wrap interface calls in blueprint you incur an extra overhead, add in all the extra checks you had to do and its just not worth it.

both have their uses though so dont let that scare you off

1 Like

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