Cast event when (Variable change)

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

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 mode is used for single-player and local multiplayer games. It will run both server-side logic and client-side logic as appropriate for the local players.

However, for those who, like me, are working on a multiplayer project and want to do this only on the client and at the same time not overload the server and network - alas, I don’t have an exact way to solve this yet.
Yes, you can create and use a “set function” instead of a just “Set”, but this option will only work when changing the values (calling the function) ​​​​in the blueprints, and not when the value of the variable is directly changed (like in maping).
And of course, you can always use some C++ custom class and code, but we’re not here for that :sunglasses:

So for now, I can only suggest a method that is used in the Lyra project - create a second variable that will be every tick/period of time, check if its value differs from the target one and when this happens - call the event and update this variable value.
image

2 Likes