Optional Enum Parameters help

hi all im trying to make an animation script for my character. it turns out my method uses enums, then casting them into strings.
but unity throws an internal error. whenever i try to make the optional enum parameters for my setAnimations function.

using UnityEngine;
using System.Collections;

public class Calnan : MonoBehaviour
{
    public Transform Camera;
    public Transform CamPoint;


    public string CurrentState;
    public enum ProneState
    {
      Null,     
      Idle,     
      Crouch,
      Standing,
     
    }
    public enum ActState
    {   Null,
         Fire,
         Jump,
         Aim
    }
    public enum MoveState
    {  Null,  
        Walk,
        Run,
        StrafeLeft,
        StrafeRight,
    }

    ProneState Prone;
    MoveState MoveDir;
    ActState Act;
    
    // Use this for initialization
    void Awake()
    {
        Prone = ProneState.Standing;
        Act = ActState.Null;
        MoveDir = MoveState.Null;

    }
    void Start()
    {
        animation.GetClip(ProneState.Idle.ToString());
        
        
       
    }

    // Update is called once per frame
    void Update()
    {
        animation.Play();
       
        CheckState();
        Camera.position = CamPoint.position;
    }
    void CheckState()
    {
        bool CrouchMode = false;

        if (Input.GetButton("Fire1"))
        {
            SetAnimation(ProneState.Null,ActState.Fire, MoveState.Null);
        }
        if (Input.GetButton("Crouch") )
        {
            if (!CrouchMode)
            {
                SetAnimation(ProneState.Crouch, ActState.Null, MoveState.Null);
                Prone = ProneState.Crouch;
                CrouchMode = true;
            }
            CrouchMode = false;

        }
      
        else
        {
            SetAnimation(ProneState.Idle, ActState.Null, MoveState.Null);
        }

      
 
    }
   
   public  void SetAnimation (ProneState prone  , ActState Action , MoveState Move )
    {
        if (prone == ProneState.Null)
        {
            prone = Prone;
        }
        if (Action == ActState.Null)
        {
            Action = Act;
        }
        if (Move == MoveState.Null)
        {
            Move = MoveDir;
        }

        string newAnim1 = prone.ToString();
        string newAnim2 = Action.ToString();
        string newAnim3 = Move.ToString();

        string newAnim = newAnim1 + newAnim3 + newAnim2;
        animation.clip = animation.GetClip(newAnim);
        CurrentState = newAnim;

    }
}

being a internal error im convinced that unity blocks or doesn’t support them for what ever reason, any work arounds?

You’ve tried selectively removing chunks of code to narrow down what’s causing the error?

(Internal errors are always a bug and never your fault. They should probably be reported).

yes for some reason i posted the solved code, originally the Enums at the SetAnimation were optional parameters

as soon as i made them required parameters the error disappears. if i used an optional parameter of a different type ( lets say string). the error doesn’t appear.

optional enum parameters in your Functions will cause this error!!!.

Have you sent a bug report? I found it annoying too, wasted half an hour and figured it out. :rage:

Both Visual Studio and MonoDevelop (and me) don’t see any problem on optional enum parameter, but Unity just doesn’t like it.

By the way, I’m using Unity 4.5.2f1

Nope, they work just fine for me.

It is weird that it doesn’t always cause that error.
In my case, it occurs only if
(1) the class is generic and
(2) has getter and setter to store and return the enum value.
And whether it extends from MonoBehaviour doesn’t affect the result.

It still happens in Unity 4.5.3f3.

What is “State”? Whatever it is, it doesn’t look like it would be convertible to each of the other classes?

I think I saw this once… It’s not an issue with Unity, it’s a runtime issue with Mono. So until Unity updates their version of Mono, just stay away from optional param when it crashes. :stuck_out_tongue:

@StarManta ; I think he just been lazy and didn’t write the whole type.