How to make shared variables come up as nested menu

jfcarter

New member
Hello Behavior Designer Community,

I am currently working on enhancing the usability of the Behavior Designer editor for a project where I have a significant number of shared variables. To organize these better and streamline the process of assigning these variables within tasks, I am looking to implement a functionality similar to Unity's Project tab's right-click context menu—where you can navigate through nested menus (e.g., Create > Folder).

Here's the basic setup of my custom shared variables class:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime;

[System.Serializable]
public class CustomStats
{
public SharedFloat maxHealth;
public SharedFloat walkSpeed;
public SharedFloat runSpeed;
public SharedFloat angularSpeed;
public SharedFloat engageDistance;
public SharedFloat attackRange;
public SharedFloat attackDamage;
}

[System.Serializable]
public class SharedCustomStats : SharedVariable<CustomStats>
{
public static implicit operator SharedCustomStats(CustomStats value) {return new SharedCustomStats { Value = value };}
}

The current functionality allows me to create a CustomStats class which includes several shared variables like maxHealth, walkSpeed, etc. However, in the Behavior Designer tasks, I cannot directly set, for example, the walkSpeed without first setting the entire CustomStats object. This approach is somewhat cumbersome and does not provide the clean, easy-to-navigate interface I aim for.

Ideally, I would like to have a nested menu system in the inspector where I could select a SharedCustomStats variable and then have a submenu or similar mechanism to select individual properties like walkSpeed directly.

Does anyone have experience with customizing the inspector for Behavior Designer to this extent, or could anyone provide guidance or suggestions on how this could be implemented? Any help or pointers towards relevant documentation or examples would be greatly appreciated.

Thank you!
 
With the current design SharedVariables are not inherited. The logic behind this is because if you were to share the entire SharedCustomStats variable with multiple tasks then the same nested variables must also point to the same reference.

Most of those variables look like they will stay consistent through the lifetime of the agent so instead of assigning individual values to them I instead recommend that you use the variable mapping feature. This will allow you to use properties to get the SharedFloat value and I think will offer you the flexibility that you are going for: https://opsive.com/support/documentation/behavior-designer/variables/ (variable mappings is described at the bottom).
 
Top