Thomas
Thomas

Reputation: 1212

Unreal Engine 4 Blueprints - how to set branch condition on get actor of class

I have been working on a simple game in Unreal Engine 4. I am trying to make it so when a player is hit by a cube they take damage. However, I am stuck on creating a condition. I have previously used:

Previous Health management to set up a condition where a player only takes damage if they are touched by the cube (In my cube pawn blueprints).

This doesn't work however - when trying to set-up my health bar:

Current attempt

This shows that I am now using entirely new variables to attempt to get a successful updating bar. Without setting it up so when a cube hits the player, the player takes damage, the player will take damage from simply jumping at walking into other surfaces.

I have created a function that successfully updates my current health and max health so I don't need to show, or need help with the maths or updating the widget. Is there a way for me to use the branch to create an if statement that checks the contact is form a cube?

I am quite new to blueprints and have mostly developed through the use of tutorials. If you need clarity on my question or you don't understand what I am asking please leave a comment and I will try to update. I have looked long and hard for an answer, but I have found that Unreal Engine 4 hasn't got many questions that I can tailor the answer to my situation. If the answer is already in another post on this website, comment saying so and I will remove this post.

Thanks for any help you can give me :)

(This also has a itch.io page for me to quickly share to my friends so I will also credit the person who helped me there)

Upvotes: 0

Views: 5246

Answers (1)

Daniel
Daniel

Reputation: 1481

If I've understood your question correctly, I believe you are just asking how to check if the cube has hit the player character and not some other actor.

Instead of using an if statement as you suggested, you can just cast the Other Actor property to your first person character. If the cast is successful then it hit the character, if the cast fails, it hit something else. You can then call the damage function which you said you've already created. Below is a basic example you could use in your cube blueprint. You will also need to make sure you have a collision box surrounding your cube mesh (and your character, but I can already see that in your screenshot).

Event ActorBeginOverlap -> Cast to BP_FirstPersonCharacter

Upvotes: 2

Related Questions