How to access Enum on Blackboard through script

Hi, I’m using a ‘Set Variable Value’ Action to change an Enum on the Blackboard when my script returns Status.Success and all runs fine, but instead of manually changing the Value in the dropdown window is there a way to change it in the script before Status.Success is called?

I did make an Action script to try and change it, then call this when Status.Success instead of the Set Variable Value Action -

[SerializeReference] public BlackboardVariable<ZombieState> Enum;
    [SerializeReference] public BlackboardVariable<int> EnumValue;

    protected override Status OnStart()
    {
        EnumValue.Value = 2;

        if (Enum == null || EnumValue == null)
        {
            return Status.Failure;
        }
        Enum.ObjectValue = EnumValue.ObjectValue;

        return Status.Success;
    }

No errors, debugged it, it runs but it doesn’t change the value and switch to another state, I think I know the line 'Enum.ObjectValue = EnumValue.ObjectValue; ’ is the problem, or can’t it be done in an Action script? Any help would be gratefully appreciated, thanks.

Great, it does work, I had a lot more script in there and I removed what I didn’t want before posting and now it works, great …

using System;
using Unity.Behavior;
using UnityEngine;
using Action = Unity.Behavior.Action;
using Unity.Properties;

[Serializable, GeneratePropertyBag]
[NodeDescription(name: "Set Enum Action", story: "[AIZombieController] [Enum] [EnumValue] Action", category: "Action", id: "f72051b6c0f2d8bf255b8793d81eec80")]
public partial class SetEnumAction : Action
{
    [SerializeReference] public BlackboardVariable<ZombieState> Enum;
    [SerializeReference] public BlackboardVariable<int> EnumValue;

    protected override Status OnStart()
    {
        EnumValue.Value = 3;

        if (Enum == null || EnumValue == null)
        {
            return Status.Failure;
        }
        Enum.ObjectValue = EnumValue.ObjectValue;

        return Status.Success;
    }
}

Hey @Griffo , I’m a bit confused about the issue you were having but it looks like you solved it :sweat_smile:

Just a small note, the BlackboardVariable should never be null, it’s only object references that could potentially be null, so you should be able to safely remove the following code :slight_smile:

1 Like