Alternate between calm and heavy breathing based on oxygen value

Hey guys,

My first post here but not my first time here. Spent many MANY hours reading through posts, mainly to find solutions to problems I’ve faced with blueprints and getting certain aspects of my game working. I am very VERY new to blueprints with no coding knowledge, I am primarily a 3D/2D Artist, EEKS.

Now on to my current problem. I have a player who has an oxygen bar which constantly goes down as you can see from my OxygenLeak Function image below. I also have an Oxygen Thrust which minuses from the oxygen amount. All of this works great, I have pickups too that add oxygen with a clamp to ensure the oxygen value will max out at 100.

Now what I want to do, and I have tried and TRIED, is have my players breathing change from calm to gasping when the oxygen value is below 50 (the max is 100) via the Oxygen variable. I can not for the life of me get this to work. I believe it is due to the fact in the character blueprint only the starting value is being read with is 100 and not the ‘live’ value do only the calm breathing plays with no change once oxygen goes below 50.

I have tried adding this to an event tick but that just plays the audio every second and managed to get it to work using a do once but then had difficulty reverting back to the sounds when oxygen went over 80, it would not repeat without the crazy sounds playing every second.

I’m not sure if I’m making much sense, especially after spending so many hours trying to figure this out! :frowning:

Please help!

Thank you both of you! It worked! I have attached the blueprint for the breathing control. I ended up using a sequence as it’s the only way I know of to allow more than one output from an event tick.

Doe this look ok?

It worked, Thank you for you help! :slight_smile: I have added a comment with my new blueprint. Does it look ok?

This may not be the best solution but personally I’d go for a event system. Where you trigger some custom events based on the oxygen change.

That adds at least some layer of abstraction and makes the graph a bit smaller when working with it.

Next of all event Tick is actually very right. You need to check all the time. If you have it once at the beginning it will only be called once, compare the initial value and never change because that part is never called again.

DoOnce is a good start. You want to add that right after checking for a value. So let’s say you check if it’s below 50. If so, DoOnce, call your heavy breath event and reset all other DoOnce.

Then check if it’s above 80. If so, DoOnce, call your normal breath event and reset all other DoOnce.

(Do Once will only allow one input through. Until something enters “Reset”. Then it will allow one more impulse through until “Reset” is called again).

And the separation in events is simply so you can rather easily add more effects later on. Like HUD modifications and the likes without going in the actual checks and moving tons of stuff around.

Does that make sense?

If I understand you correctly, you could put a branch right after the tick that is doing your oxygen calculation that tests if current oxygen < 50% of max oxygen, then use a sequence and a do once node after each branch result. First output of sequence plays the sound (and stores it to a variable) and the second goes into ‘reset’ on the opposite branch. Then go into your sound asset and set it to looping.

It worked, Thank you for you help! :slight_smile: I have added a comment with my new blueprint. Does it look ok?

Thanks a ton Erasio!