Shared Variable Change Notification

Ruka

New member
Hello!
I've looked through the docs a few times and can't seem to find what I am looking for. As far as I know, shared variables are just properties. So, would it be possible to set up a C# event that reacts to a shared variable changing (being set)? Seems like a quick OnValueChanged event would be more efficient than checking the variable every frame to see if it has changed.
Thank you for your time,
-Luka
 
What is your goal? SharedVariables are classes and not just properties, maybe you are referring to property mappings?
 
What is your goal? SharedVariables are classes and not just properties, maybe you are referring to property mappings?
My goal is to have a shared variable like health for instance, and have an event that other classes could subscribe to when that shared variable changes. So a health shared variable could send an event to a number of classes to notify them that it has changed. One might go to the UI to update the value, another might go to a class that's responsible for playing different particle effects if the character is hurt or healed etc.

Property maps could work for this, but as I understand, it requires making a duplicate property in the other class, and that may not be desirable if I want to have many systems all responding to many shared variables. That feels like a lot of duplication for a scenario where I simply want to pass a value. I'm still relatively new to C# so if I'm thinking about this wrong, please let me know!

Edit: I was also meaning to ask, if you map a shared variable like a vector3 to a transform's position, or just a general property that you've set up in a class, does that use reflection? I was assuming it does since the get/set property value task is also listed as reflection, but wanted to make sure.
 
Last edited:
Ah, I see. There are multiple ways a SharedVariable can be set:

- The Value property
- Property Mappings
- SharedVariable.SetValue

There isn't an event system with any of these but you could import the runtime source and add one.

Edit: I was also meaning to ask, if you map a shared variable like a vector3 to a transform's position, or just a general property that you've set up in a class, does that use reflection? I was assuming it does since the get/set property value task is also listed as reflection, but wanted to make sure.
Yes, it does. But it's a one time hit because it creates a delegate which is fast.
 
Top