I need help creating an IF/THEN branch

Hi everyone. I am a total beginner with Unreal Engine. For my starter project, I’m making a basic arena shooter. In this game, you can collect two powerups: One will refill your health, and the other will give you temporary invincibility. The programming behind both of these powerups work just fine. Both powerups are children of a master powerup class. What I need help solving is how the game will determine which of the two powerups you just collected. Did you touch the health pickup? Then call the AddBonus event. If not, then did you touch the shield pickup? Then call the AddShield event. That’s all I want it to do but I can’t figure it out. Any help would be much appreciated!

It’s only letting me upload one picture, so here’s the parent (or master) blueprint. Right now, it successfully calls the AddBonus event in the health pickup. I just need it to also call an event called AddShield, if that’s what the player touched.

Does this help? :innocent:

Thank you so much for responding!

But it doesn’t work, I’m sorry. :frowning: I had another idea to go to my Component Begin Overlap event, drag off the “other comp” pin, and plug it into an equality (==) operation. There, I check if the other component is equal to my HP Pickup Blueprint. If it is, then call the add bonus event. If not, call the shield bonus event. When I try this, the shield works fine, but now the heath pickup doesn’t. I have a screenshot of my idea, but I’m open to other thoughts if you have them!

Sorry again.

You add either one or the other child bonus to the level, there is no need to define either, they are already defined by the fact of being on the level.

All you need to do is to make ONE event in the parent class to activate the bonus, and then in each of the child classes OVERRIDE this event with the effect that each of them gives.

1 Like

The reason the other one doesn’t work in that screenshot of yours is because the Cast To node for the AI never gets executed. The Cast To node before that always succeeds so it never executes the Cast Failed pin. You’d need to plug your other Cast To node after it’s default execution pin. So it should be between the Cast To node for the player and the branch node in the execution order.

Fix this and it should work :blush:


About my initial suggestion, could you please expand on that:

Maybe I could spot the mistake in your implementation if you send a screenshot of your attempt.

Okay, I’ll try to elaborate further on why that didn’t work. I followed your screenshot as closely as I could. What I did differently began at the two Cast To nodes. My blueprints are called HP_Pickup and Shield_Pickup. Aside from the names (which I don’t think really matters) my Cast To nodes were the same as yours. I wonder if my problem was at the two event calls at the end. Instead of calling the same event, I had the “heal” branch call one event called AddBonus, and the “shield” branch call a different event called ShieldBonus. That’s all I did differently, and the result was that the health pickup worked just fine, but the shield pickup became uncollectable. I just walk right through it.

You know what’s really weird? I swear I did this before, and nothing happened. I tried this a second time, and now it works!

My parent class is calling just one event “AddBonus”. Both children of this parent class begin with that same event call, and now, I can pick up the health powerup as well as the shield! So yes, I think I did need to override the event.

The first time I tried this, I created the event AddBonus in both the shield and health blueprints. For some reason, the engine didn’t like having two identically-named events in two different blueprints, and it automatically named one of them “AddBonus_1”. I’m really not sure why it did this, so I assumed it was the wrong thing to do. But hey, it works now! Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.