Issues with an enum not passing

So I have a block of code which is being passed an enum from anothe c# script. Everything is working fine apart from one little thing which is settng leftHandState and rightHandState to the passed enum value. I have debug.log the incoming variables hLeft and hRight and they return the correct enum. But when I go to make leftHandState or rightHandState = to the passed enum value they do not change but stay at the default value for the enum.

This is the code for the specific file below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum HandStates { Default, Fist, ThumbUp, PointingThumbUp, Pointing, IndexFinger };
public class SystemManager : MonoBehaviour
{
    //GameObject States
    public CasualtyState casualtyState;
    //hand Presence
    private HandStates leftHandState;
    private HandStates rightHandState;
    public WristReturnMenu wristReturnMenu;

    public void SetLeftHandState(HandStates hLeft) {
        Debug.Log(hLeft); //This is logging the correct enum value
        leftHandState = hLeft;
        Debug.Log(leftHandState); //This isn't changing
    }
    public void SetRightHandState(HandStates hRight) {
        rightHandState = hRight;
    }
    private void Update() {
        Debug.Log("Left Hand State: " + leftHandState);
        Debug.Log("Right Hand State: " + rightHandState);
    }
}

Since you’re accessing the Set functions from outside of the SystemManager class that means you have another enum called HandStates, and that’s why you’re having this problem.


Those are two different enums. You have a SystemManager/HandStates and a “OtherCode”/HandStates. You can’t make them interact in the same way that you can’t do Vector3 = Vector2.


The quickest way for you to fix this in your code would be to pass along an int Index instead of the whole enum type, then use the index to assign the value you want to SystemManager/HandStates.

The correct way would be to create a “BodyTypes”.cs scriptable object class. Then make your HandStates enum there, and use that type to create enums in all your code.

public class BodyTypes : ScriptableObject
{
       public enum HandStates {ThumbsUp, ThumbsDown};
}

This is how you would declare a new HandStates type in the rest of your code:

 public BodyTypes.HandStates thisHandState;
 public class SystemManager : MonoBehaviour
 {
     //GameObject States