I have an actor blueprint called BP_Interactable_Object that I use for objects that the player can interact with (doors, drawers etc.) I made the blueprint very dynamic in that I can swap the mesh as well as change the type of animation (move or rotate). I now want to add some functionality to allow the actor “Activate” (trigger) an event in the level blueprint like causing a lift to move or turn off a light etc., but I’m not sure how to go about doing this and all of the searches I’ve done say that you cannot communicate from an actor to the world which seems unbelievable to me.
I started by creating a custom event in my BP_Interactable_Object called “Activate”. I then get the game mode, cast it to my game mode and then trigger an event inside the game mode called Interactable Object Activate. The reason I did this was because the game mode is a requirement of every level.
I then created a function inside my game mode blueprint called Get Nearest Interactable Object. This gets all actors of the class BP_Interactable_Object and grabs the one closest to the player so that its not activating all of the Interactable Objects (or only one of them).
From here though, I’m not sure how I can send this info over to the level blueprint to allow for triggering level specific events.
If it is truly not possible to communicate from an actorBP to the levelBP, then how would one go about enabling interaction with an object to trigger a dynamic and custom event? I.E. when I interact with one door, I might want it to turn off a light in the level, whereas I may want another door to trigger a skeletal mesh’s animation. I want to allow the level designer to create these links between objects when the door is interacted with and as far as I know, that sort of thing is only possible through the level blueprint by getting a reference to a specific actor.
I had an epiphany this morning when I woke up and realized I was trying to approach this in a completely convoluted way.
I’m writing this update to help anyone else who might be having a similar problem when trying to understand how to communicate between a level blueprint and an actor. The first thing I realized is that there is a specific reason why the communication between the level BP and an actor BP is one way. The level has to know about each of the actors placed in the world, but the actor doesn’t need to know about the level. This would make the code overly complex.
If you want to create a system where one of the actors in your scene can communicate with the level in the same way I wanted to - i.e. open a door and trigger a level event - then all you need to do to accomplish this is create two booleans inside your door blueprint. Call the first one Activator?, and make it a public variable. Then when the level designer is placing the door in the world, they can check off the Activator bool if they want it to activate something.
Name the second boolean Active? and set this to true just before the animation happens and set it to false when the animation is finished.
Then inside the level blueprint, you simply get a reference to that door and use a branch to check to see if the Activator? and Active? states are true. If they are, you can run whatever code you like. DONE!
Hi. I just want to advice you to learn Event Dispatcher.( Event Dispatchers | Unreal Engine Documentation ).
This is the way you can make actors to call level blueprint’s functions. The concept is following: Level BP subscribes to actor’s events and when they’re fired inside actor BP, Level BP handles them by calling appropriate function.
I really like what you did here! I had a quick clarifying question: Can this technique also be used to “trigger” a matinee actor from inside a different actors event graph?
Technically you could use this to trigger anything but plastik21 is right, Event Dispatchers are the way to handle something like this. There’s also less overhead because you’re not using Event Tick to constantly check for the event to occur.