# "On value changed" event?

**URL:** <https://forums.unrealengine.com/t/on-value-changed-event/1164770>\
**Category:** Blueprint\
**Tags:** variables, float, unreal-engine, nodes, Blueprint, question\
**Created:** [May 13, 2023, 7:13pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770 "2023-05-13T19:13:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fallerrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fallerrr/32/482685_2.png) [@Fallerrr](https://forums.unrealengine.com/u/Fallerrr)\
**Post date:** [May 13, 2023, 7:13pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/1 "2023-05-13T19:13:10Z")

</div>

So I wanted to apply a speed boost to the character when they equip the speed boost ability. I could just make it so that if they have it equipped it changes the value to make them faster, but the problem with that is the fact that the “Max Walk Speed” value is changed in multiple blueprints, so I’d have to add that condition every time I want to apply the speed boost. I want to make it so that every time the Max Walk Speed variable changes it multiplies the speed by 1.15, but I couldn’t find a node for this. Please help.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/d/b6dae964cf1e6f01d8f6fa03b78a2bf5c0860912.png)

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [May 13, 2023, 7:41pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/2 "2023-05-13T19:41:40Z")

</div>

Hey there @Fallerrr! There’s a number of things you can do for this, but the simplest being instead of changing the variable directly, you make it an event or function to change it. Then you can just send a new custom event over (since it’s in the same actor) named UpdatedMovementSpeed. That said, when handling a core variable like this, having some event/function is best due to how messy allowing just any objects to change the speed of the character.

---

<div class="post-metadata">

**Author:** ![Fallerrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fallerrr/32/482685_2.png) [@Fallerrr](https://forums.unrealengine.com/u/Fallerrr)\
**Post date:** [May 13, 2023, 7:58pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/3 "2023-05-13T19:58:32Z")

</div>

That would work if I did it earlier. I would do that if I knew every place I modified the value. If I only do it the the parts where I remember changing it, then if it changes because I missed a certain bit of code, then there won’t be a speed boost until the code that I modified is executed again.

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [May 13, 2023, 8:50pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/4 "2023-05-13T20:50:35Z")

</div>

I understand! Refactoring can definitely be a pain later in a project! Though if you are intending to maintain the project it might save you a major headache in the future to do it before it gets too big, as tech debt can be painful!

Though, according to this post, if your game isn’t multiplayer (and not going to be) you could use the rep notify feature which is basically the same thing, but made for multiplayer replication. Delegates are also a possibility, but that’d also mean you’d have to go back and refactor the same way anyway.

> [@Cast event when (Variable change)](https://forums.unrealengine.com/t/cast-event-when-variable-change/415961/6):
>
> For those who, like me, are faced with this task, I can recommend the following tipping_hand_man If you are developing a singleplayer game, you can use the RepNotify for Replication setting of the varible and use generated OnRep\_ function to call the event on the varible change. This method works in single mode [because](https://docs.unrealengine.com/5.0/en-US/networking-overview-for-unreal-engine/#networkmodesandservertypes) Standalone: The game is running as a server, that does not accept connections from remote clients. Any players participating in the game are strictly local players. This mod…

---

<div class="post-metadata">

**Author:** ![Fallerrr](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fallerrr/32/482685_2.png) [@Fallerrr](https://forums.unrealengine.com/u/Fallerrr)\
**Post date:** [May 14, 2023, 1:51pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/5 "2023-05-14T13:51:38Z")

</div>

it works now, Thanks!

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [May 14, 2023, 7:33pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/6 "2023-05-14T19:33:48Z")

</div>

I had never though about using Repnotifies for this however, so keep an eye out of issues it may cause. In theory there shouldn’t be any considering it’s purpose built to fire an event when something changes, but if you ever include any multiplayer components to your game things will definitely be a bit odd.

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [May 14, 2023, 9:09pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/7 "2023-05-14T21:09:06Z")

</div>

OnRep still has the “but who triggers the Rep?” problem.  
The real solution to this problem is to use the Gameplay Ability Framework.  
That’s what it’s for!

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [May 14, 2023, 10:24pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/8 "2023-05-14T22:24:38Z")

</div>

I agree! Though setting up GAS would be far more than just a refactor for this user’s use case. That and it still requires C++ to setup, so I figured the shorter refactor or the hacky workaround might work out a bit easier. Though with multiple actors accessing direct variables, there is likely a refactor in the future either way!

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [May 15, 2023, 7:18pm UTC](https://forums.unrealengine.com/t/on-value-changed-event/1164770/9 "2023-05-15T19:18:28Z")

</div>

Here is a handy macro I use a lot:

> **[Do While Special | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/mbL/unreal-engine-do-while-special)**
>
> While True
> While False
> Changed to True
> Changed to False

you could run this on tick or a timer, then fire event from On Changed execution pins. I can understand the desire to have it handled separately from like a Setter, just because then you have a clear separation of responsibility and more searchable code.

Like if sometimes you handle event dispatches when using a Setter and other times not, then you have inconsistent code and it causes confusion. Whereas if you have like a system which is just for handling dispatches based on variable changes, then you have more of a single source you can go to and find via text search. Of course the key is just to have consistency no matter what approach you take. It won’t always make sense to poll for value changes constantly if they will only ever change from an event but that’s just situational judgement calls to make.
