Adding Global Variables (Editor Scripting)

jeo77

New member
Hey, so I've dug around in the forums and on this discord but I can't seem to an answer to this one: I have a huge collection of variables in the form of scriptable objects (think like single floats, single ints, strings etc. all each saved as a Scriptable Object). I want to be able to access these from behavior trees, so I was planning on having an editor script that searches my project for any of these assets, adds a respective global variable for each, and then maps that variable to the appropriate scriptable object at runtime. So far, I can only seem to either add Global Variables by hand (not realistic, as multiple designers are often adding/removing this scriptable object variables to the project), or at runtime - which means they can't be accessed by designers in the editor.

So is there some way to programmatically add global variables & variable mappings while just in editor (not runtime)?
 
You can set the property mappings value through code and then serialize that. This post looks similar to what you are going for:

 
Hey, so I've dug around in the forums and on this discord but I can't seem to an answer to this one: I have a huge collection of variables in the form of scriptable objects (think like single floats, single ints, strings etc. all each saved as a Scriptable Object). I want to be able to access these from behavior trees, so I was planning on having an editor script that searches my project for any of these assets, adds a respective global variable for each, and then maps that variable to the appropriate scriptable object at runtime. So far, I can only seem to either add Global Variables by hand (not realistic, as multiple designers are often adding/removing this scriptable object variables to the project), or at runtime - which means they can't be accessed by designers in the editor.

So is there some way to programmatically add global variables & variable mappings while just in editor (not runtime)?
Hey Justin, I appreciate the reply.

I've gone through this thread (including the thread referenced within it) but I'm still having issues here and need to bug you for a bit more help - sorry. I've looked at the SetPropertyMapping function example by Zurigan but it seems more geared towards properties that have owner GameObjects and get initialized with the InitializePropertyMapping call.

I think it's something like this? But then I'm not sure what on 'SharedString' needs to be set to construct the mapping here. I'm seeing fields for IsShared, IsGlobal, PropertyMapping, PropertyMappingOwner, etc but I'm not sure how those would be setup here.
 

Attachments

  • Screenshot 2024-06-13 003753.png
    Screenshot 2024-06-13 003753.png
    191.7 KB · Views: 3
Ahh, I misread this initially. Unfortunately global variables are not able to use the property mapping feature. This is because property mappings take a GameObject which is required and project level assets cannot point to scene level assets.

This is a deeper structural level change which you could make by modifying the runtime source, but I will also see if I can support it in version 2 of Behavior Designer.
 
Back
Top