Hello guys,
I’m a newcomer into the blueprints and I couldn’t find an answer for my issue, which could very well mean I try to approach it in a bad way. It’s for the new Unreal Tournament 4, but the question is more related to Unreal engine.
I’m blueprinting a button, which, after it’s pushed, buffs the character pushing it.
I’ve pretty much copy-pasted the button and it works flawlessly. The think I have troubles with is the buffing part.
I’d like the buff to be an event - when the character is hit, do something.
I’ve created a very simple event by clicking the green + button for ‘On Take Any Damage’ event in the ‘Player’ variable (BaseUTCharacter class reference). It looks like this:
The variable is correctly set (I print the player’s health every time he pushes the button) but the event is never triggered.
However, if I add the event directly in the BaseUTCharacter blueprint, it fires every time the character is damaged:
I don’t understand what’s the difference between those two examples.
Can’t blueprint’s event fire when its reference is used in another blueprint? Then why would there be the green + buttons in the variable creating exactly that?
Do I have to bind the variable first? But why don’t I have to bind the even when it’s in the blueprint? And if I try to use ‘Bind Event on TakeAnyDamage’, it wants ‘self’ reference instead of ‘BaseUTCharacter’ reference and displays an error (because it wants event for my blueprint presumably).
All I’ve found are events for the one blueprint and not across two. Am I understanding it wrong or missing something?
The player is damaged for 10 HP once he pushes the button using the ‘Apply damage’ function and I print the player’s health as well. Both are working correctly. I’m working only with this single BaseUTCharacter variable.
The difference between the two examples is that Event AnyDamage is a BlueprintImplementableEvent which fires in response to a C++ function call and can only be implemented by the actor blueprint that the event belongs to. OnTakeAnyDamage is a [multicast delegate][1] that other classes can use to receive events about an object, but you need to explicitly bind to it.
In your button blueprint you’ll need to do something like this
To set that up, drag a pin from the character reference to an empty spot on the graph and select Bind Event to OnTakeAnyDamage. Then drag off of the red Event pin and create a Custom Event node.
When you’ve finished using the delegate, use Unbind Event from OnTakeAnyDamage, with it’s event pin connected to the same Custom Event, to clean up.
edit: as for why the event created with the green button doesn’t work, I think it only creates the event node for you but you still have to bind to it yourself. The custom event method above is just another way of setting it up.