How to trigger level blueprint event from Actor BP?
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.
Here's a look at my blueprints so far:
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.
Hi. I just want to advice you to learn Event Dispatcher.( https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/EventDispatcher/index.html ). 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 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!
Here's a look at my blueprints:
I don't know why this was such a hard lesson to learn, but there you have it. Hopefully my question and answer will help someone else.
Follow this question
Once you sign in you will be able to subscribe for any updates here