Should I just use casting instead of making all sorts of interfaces?

I have a lot of blueprint actors that share information with each other. For example, you can pick up an item and while holding it, click on another actor and it will pass some info to that actor. Example: Press on a jar while holding a beaker with liquid in it, the jar fills up with liquid and a string is passed to the beaker about what kind of liquid it was filled with.

Two things are set in this process:

  • A boolean (IsFilled) that sets the visibility of the liquid component in the beaker.
  • A string (LiquidType) that determines other logic downstream.

So I have heard that using Casting in Blueprint is not necessarily recommended in Blueprint, since it doesn’t have the concept of headers and thus whenever you cast to an actor blueprint, it loads the entire actor’s data into memory, which can be slow and wasteful.

In response, I thought to myself: “Well, then I’ll just make an interface Set Bool and one called Set String and call that instead of casting to an actor.”

But what has happened is that I’ve created 4 of these types of interfaces at this point:

  • Set Bool
  • Set Vec
  • Set String
  • Set Float

and I’m starting to feel silly about it. Is this really the way to go? Also, if I have to set more than one float, would I not need:

  • Set Float1
  • Set Float2
  • Set FloatN
    ?

This seems redundant and stupid. This can’t be the way to go, right?

How do you do it correctly?

There are other downsides to using casting, like tight coupling.

I got around it by sending a payload structure

You can use it to send or receive just about anything

image

( you don’t have to display all pins )

2 Likes

So what you’re telling me…is that it is perfectly legitimate to do this?

I do it. I don’t know if that makes it legit :slight_smile:

Payload is much easier though, as you only have to code one interface.

This looks really helpful. I need to add this to my project :smile:

1 Like