Spaceship with multiple interfaces; blueprint interfaces?

I’ve got a standard BPI_Interact, which is great for doing things like possessing a spaceship when the player is within a collision box and presses the interact key.

But let’s say in the same spaceship I have another collision box that teleports the player outside the ship. In order to interact with that collision box, how would I do it?

I thought about using variables and doing if/thens with the existing interface (e.g. If Pilot do this, if Exit do that), but it seems like there must be a more elegant way to do it? If I add warp drive, scanner, entrance collision, turrets, etc., the if/thens could get pretty gnarly!

Another idea was using child actors, but that seems a little clumsy too, since I’d have to figure out how to reference various systems/locations in the ship and the child actor would be pretty specific to one actor, which probably defeats some point or other.

To sum up: I’d like the player to, say, walk up to a collision, hit InteractKey and teleport inside, then walk up to something like the pilot station, hit InteractKey and start piloting the ship. Since both collisions (and more to come) are part of the same actor, what’s the best way to interact with many interactables within one actor?

Even with one interface, you can have many different functions. Not just ‘interact’, but ‘exit’, ‘reenter’, ‘pilot’…

When you have multiple collision volumes, ‘on begin overlap’ won’t cut it, and you need the spaceship to use ‘on component begin overlap ( volume name )’.

Aright, let me describe an implementation:

Spaceship has BPI_Interact implemented, which has functions “Interact”, “Pilot”, “Exit”

Player has an Interact action/key

Player walks up to pilot area (collision box), presses the interact action key, which calls “Interact” on the BPI.

At that point, how to access these other functions? Does the “interact” function do something like check for what the player is overlapping and then choose another function based on that? I can see how that would work, but would that be the “right” way to use BPI’s in this scenario?

There is no ‘right’ way :slight_smile:

You could just use one function ‘interact’, and depending on which collision volume the player is overlapping when they press the key, do something different.

Another example, is you could do different things depending on the context, even though the player is still overlapping the same volume. For instance, ‘interact’ could mean walk into the ship, but when you’re in the ship ‘interact’ means exit again.

It’s up to you.

1 Like

I’m just hoping to avoid making code I’ll regret later xD. For the ship’s BPI Interact function, I decided to use a ForEach loop with break to find out which collision the player is overlapping and run events or functions from there. The blueprint code is pretty messy doing it that way, though. Any ideas on a more elegant solution? It only gets uglier from here!

IMO This might be a problem later on. Think it should be the other way arround: the actor whos interact function was called has to check its collision to continue the execution.

Each actor (attached or child) should have the interface. If player aims at a door, interact gets called for the door, same for each seat, lever, etc.

I think you are probably right! It wasn’t hard at all to create child actors that can refer to the main ship BP via GetParentActor and run events and functions. If child actors become an issue later on (I’ve heard some stories), it wouldn’t be that hard to just spawn them and attach them as well.

1 Like

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