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. Dismiss Notice

MethodBuilder Internal Error?

Discussion in 'Editor & General Support' started by LsMenard, Oct 9, 2014.

  1. LsMenard

    LsMenard

    Joined:
    Jan 14, 2014
    Posts:
    3
    Hey everyone.

    I have been looking for a while now and I can't find the source of this error.
    I checked all the code I wrote and everything seems fine in Visual Studio. It compile with some warnings, like unused variables, but no errors. Then when I load the assembly in unity, I have this error:

    It's preventing me from testing anything on my project since it won't launch now :(

    Anyone has an idea what I could do to fix it?

    Here is the ChangeScreen method mentionned in the error log if it helps:

    Code (CSharp):
    1. public void ChangeScreen( ScreenType screenId )
    2.     {
    3.         if (_debug) Debug.Log("[Master] Loading screen " + screenId);
    4.  
    5.         //Save screen id
    6.         currentScreen = screenId;
    7.  
    8.         //Hide any window open
    9.         WindowPrompt_Enter(WindowPromptType.NONE);
    10.  
    11.         //Reset flags
    12.         inLevel = false;
    13.         inEditor = false;
    14.         inPrompt = ActionPromptType.NONE;
    15.         currentTool = EditorTool.NONE;
    16.  
    17.         //Do specific actions for screens
    18.         switch (screenId)
    19.         {
    20.             //Loading Screen
    21.             case ScreenType.LOADING:
    22.                 ui.LoadScreen(screenId);
    23.                 break;
    24.  
    25.             //Main Menu Screen
    26.             case ScreenType.MAINMENU:
    27.                 ui.LoadScreen(screenId);
    28.                 break;
    29.  
    30.             //Editor welcome screen
    31.             case ScreenType.EDITOR_SPLASH:
    32.  
    33.                 inEditor = true;
    34.                 inLevel = false;
    35.  
    36.                 //Load UI
    37.                 ui.LoadScreen(screenId);
    38.  
    39.                 //hide tool menu tool
    40.                 Editor_Tools_Enter(EditorTool.OFF);
    41.  
    42.                 break;
    43.  
    44.             //Editor in map screen
    45.             case ScreenType.EDITOR_INMAP:
    46.  
    47.                 inEditor = true;
    48.                 inLevel = true;
    49.        
    50.                 //Load UI
    51.                 ui.LoadScreen(ScreenType.EDITOR_INMAP);
    52.  
    53.                 //show tools menu
    54.                 Editor_Tools_Enter(EditorTool.NONE);
    55.  
    56.                 //Select default editor objects
    57.                 DataUnit defaultUnit = data.units[0] as DataUnit;
    58.  
    59.                 if (defaultUnit != null)
    60.                     Editor_UnitType_Select(defaultUnit);
    61.  
    62.                 if( mapData.layers.Count > 0 )
    63.                 {
    64.                     DataMapLayer defaultLayer = mapData.layers[mapData.layers.Count-1] as DataMapLayer;
    65.  
    66.                     if (defaultUnit != null)
    67.                         Editor_Layers_Select(ref defaultLayer);
    68.                 }
    69.                
    70.  
    71.                 break;
    72.  
    73.             //In-game screen
    74.             case ScreenType.GAME_INMAP:
    75.                 logic.Map_Load(ref mapData, false);
    76.                 ui.LoadScreen(ScreenType.GAME_INMAP);
    77.  
    78.                 break;
    79.  
    80.             default:
    81.  
    82.                 break;
    83.         }
    84.     }
     
  2. LsMenard

    LsMenard

    Joined:
    Jan 14, 2014
    Posts:
    3
    I still haven't found the source of the errors, any hint plz? :(
     
  3. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    I know this post is old, but I just faced this problem, and solved it removing all the debug.log statements.. (sic)
     
  4. Harinezumi

    Harinezumi

    Joined:
    Jan 7, 2013
    Posts:
    54
    Same as me, just faced this problem.

    I've restarted the Editor, restarted Visual Studio, cleaned and rebuilt the assemblies... but the errors persist.
     
  5. Harinezumi

    Harinezumi

    Joined:
    Jan 7, 2013
    Posts:
    54
    I've just managed to fix this. It seems the error was that I've changed a function's parameter type from int to an enum, but did not update all the calls to it that were still using an int. That would generate an implicit cast from int to enum, which seems to be OK by Visual Studio, but not Unity, and because VS is OK with it, it cannot tell you the exact problem.

    In code example:

    before:

    Code (CSharp):
    1.  
    2. // in CursorManager script:
    3. public void ChangeCursor(int cursorTypeIndex) {
    4.     currentCursorType = (CursorType)cursorTypeIndex; // works fine
    5.     // ... do some other stuff for updating the cursor
    6. }
    7.  
    8. // other script that wants to change the cursor:
    9. private void DoSomething() {
    10.     // other things to do
    11.     cursorManager.ChangeCursor((int)CursorType.PICKUP); // worked fine
    12. }
    13.  
    after:
    Code (CSharp):
    1.  
    2. public void ChangeCursor(CursorType cursorType) {
    3.     currentCursorType = cursorType;
    4.     // ... do some other stuff for updating the cursor
    5. }
    6.  
    7.  
    8. // other script that wants to change the cursor:
    9. private void DoSomething() {
    10.     // other things to do
    11.     cursorManager.ChangeCursor((int)CursorType.PICKUP); // NOT GOOD, implicit cast to CursorType that confuses Unity
    12. }
    13.