Communication between two actor classes

Hi!

In a level I have an actor as a button and another actor as a door. When the player interacts with the button the door will open.

How can I send the order to open to the door when the player interacts with the button? Using the Game Mode?

Or, I can have a reference to the door inside the Button class, and call the method to open the it.

Thanks.

So the simplest way to do this is to put the OpenDoor() function on your door BP.

In your button BP, you need to have a variable that’s a reference to the door BP type.

Make sure that variable is marked as “Instance editable”.

When you call your button function, check to make sure your variable is valid, then call the OpenDoor() function from that.

Inside of the viewport, select your button. You’ll see a space for the variable that’ll take a reference to the door. Use the eyedropper tool to directly select a door BP.

2 Likes

I don’t understand that.

Do you mean something like this?

UPROPERTY(EditDefaultsOnly, Category = Door)
TSubclassOf<class ADoor> DoorClass;

Or, probably, I can use Get All Actors Of Class | Unreal Engine Documentation.

Thanks!

There are a lot of tutorials all around the web for things like this. One of the more flexible solutions is using event dispatchers. Interaction By Event Dispatcher - UE4 Advanced Blueprints Tutorial - YouTube

Theres a good tutorial here called “Your First Game in UE5” from Andreas Suika which contains (among many other things) a door that is triggered by a pressure plate:

1 Like

If you GetAllActorsOfClass, you won’t know which door you’re trying to talk to without an additional option like an FName or an FGameplayTag.

You should be using a class ADoor*, you need a pointer because you want to talk to a specific door.

You also would want to make it EditInstanceOnly instead of EditDefaultsOnly

1 Like