Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Troubleshooting enums changing state when assigned in inspector (PLEASE HELP)

Discussion in 'Editor & General Support' started by lifetree, Mar 23, 2019.

  1. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Hi,

    I have an enum that I created for my game, and I have a public initialization of that enum so that the value can be set in the inspector. I am having a very weird issue where if I set the value in the inspector (AGE Tunnel), it keeps trying to reset to the default value (None). In the screenshot below, I had added a simple Debug.LogError to the Update method so that it would output the value of the enum to the console. As you can see, every three frames it seems to try to switch to AGE Tunnel, and then it switches back to the default value.

    Does anybody know why this would be? If I set the value in the script as opposed to in the inspector, it works great. But that doesn't really help me that much since I need to be able to assign the values in the inspector.

    I am working on consolidating all of the pertinent code spread across a few scripts to post here.

    EDIT: Here is the code from one script (Game Manager):

    Code (CSharp):
    1. private void Awake()
    2.     {
    3.            startAudioFade = true;
    4.     }
    And the other script:

    Code (CSharp):
    1. public enum MusicInNode
    2.     {
    3.     None, AGETunnel, ARW, ARWDUP, ASP, AST, Credits, CVN, DOM, FRN, FST, GTR, HDNLoop, HRP, KGS, MAZ, MAZLoop, MFC, MPL, PRM, PST, PYRAMB, QNS, RAP, RFC, ROP,
    4.     SFXReal, TMP, TNT, TNTLores, TRSHDN, WPN
    5.     }
    6.     public MusicInNode musicInNodeEnum;
    7.  
    8. void Update () {
    9.         Debug.LogError(musicInNodeEnum);
    10.  
    11.         if (GameManagerScript.startAudioFade == true)
    12.         {
    13.             Debug.LogError("startAudioFade was set to true");
    14.             GameManagerScript.startAudioFade = false;
    15.             LoadMusic();
    16.         }
    17. }
    18.  
    19. public void LoadMusic()
    20.     {
    21.         Debug.LogError("Starting Audio Fade. This should only run once per transition");
    22.         switch (musicInNodeEnum)
    23.         {
    24.             case MusicInNode.None:
    25.                 Debug.LogError("Running FadeMusic(). MusicInNode is set to " + MusicInNode.None);
    26.                 if (musicSourceOne.isPlaying)
    27.                 {
    28.                     GameManagerScript.musicSourceOneVol = 0.0f;
    29.                     gameManager.FadeMusicSourceOne(1);
    30.                 }
    31.                 if (musicSourceTwo.isPlaying)
    32.                 {
    33.                     GameManagerScript.musicSourceTwoVol = 0.0f;
    34.                     gameManager.FadeMusicSourceTwo(1);
    35.                 }
    36.                 break;
    37.  
    38.             case MusicInNode.AGETunnel:
    39.                 Debug.LogError("Running FadeMusic(). MusicInNode is set to " + MusicInNode.AGETunnel);
    40.                 gameManager.FadeMusic("Audio/Music/AGE-TUNNEL", MusicInNode.AGETunnel, musicVolumeInNode);
    41.                 break;
    42.      }
    43. }
    EDIT 2: I tried creating a new enum to test and I am having a similar issue. I don't know why it is doing this, unless this is an intended reaction, but then I need help understanding how to use enums. Here is my code:

    Code (CSharp):
    1. public enum TestEnum { CaseOne, CaseTwo, CaseThree };
    2.     public TestEnum testEnum = TestEnum.CaseOne;
    3.  
    4. void Update()
    5. {
    6.          Debug.LogError(testEnum);
    7. }
    I chose CaseTwo in the inspector and tested. Screenshot below shows the result. It is still flickering back and forth between the default and my inspector assignment.

    Please help me, I have tested a lot and I am at my wit's end here.

    Thanks
     

    Attached Files:

    Last edited: Mar 23, 2019
  2. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    I feel like such as idiot... I added this line of code to the update function:

    Code (CSharp):
    1. Debug.LogError(musicInNodeEnum + " in " + gameObject.name + " under " + gameObject.transform.root.name);
    and boom, clearly obvious there was another GO with the same script attached conflicting. I can't believe I missed that before. Hopefully this will set someone in the right direction to fix their problem.