Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

(Tiny C#) Error loading a scene : IndexOutOfRangeException

Discussion in 'Project Tiny' started by romiohasan, Jun 14, 2019.

  1. romiohasan

    romiohasan

    Joined:
    Apr 8, 2019
    Posts:
    13
    I was working with a loaded scene and made a script that works with world.EntityManager.
    Then saved the file and came back to the editor, the scene is gone from the Hierarchy and it shows the following error :

    IndexOutOfRangeException: Index has to be between upper and lower bound of the array.
    System.Array.GetValue (System.Int32 index) (at <23c160f925be47d7a4fd083a3a62c920>:0)

    Unity.Properties.TypeConversion.TryConvert[TSource,TDestination] (TSource source, TDestination& destination) (at Library/PackageCache/com.unity.properties@0.5.0-preview/Unity.Properties/Utility/TypeConversion.cs:71)
    Unity.Properties.TransferVisitor`1+TransferValueAction`3[TSourceContainer,TDestinationProperty,TDestinationContainer,TDestinationValue].VisitProperty[TSourceProperty,TSourceValue] (TSourceProperty srcProperty, TSourceContainer& srcContainer, Unity.Properties.ChangeTracker& propertyChangeTracker) (at Library/PackageCache/com.unity.properties@0.5.0-preview/Unity.Properties/TransferVisitor.cs:25)
    Unity.Serialization.SerializedObjectViewPropertyBag.FindProperty[TAction] (System.String name, Unity.Serialization.SerializedObjectView& container, Unity.Properties.ChangeTracker& changeTracker, TAction& action) (at Library/PackageCache/com.unity.tiny@0.15.3-preview/Unity.Serialization.Properties/SerializedObjectViewPropertyBag.cs:345) ...

    ...

    Tried restarting the editor, open and closing the project, nothing helps! I can not load that scene anymore by double clicking or by dragging , getting same error.
    I even commented out all the source code and still did not solve anything.

    It feels like this could possibly be a Tiny exception handling bug and something to do with editor integration.

    Any possible solution? Re-creating that scene will take a lot of time!

    Thanks!

    Update: for me, the workflow to reproduce this as follow:
    1. replaced the scene from old commit and the project opens.
    2. change a line of code from Rider and come back to the editor.
    3. Editor trigger refresh for code changes and the error comes back again. Can not load the scene anymore.
    4. Replacing the scene again works but then again with code changes error appears.
    Updated unity to 2019.2.0b5, still the same error.

    ----------
    I think I know now what the bug is.

    If I put integer number inside enum, when editor reload, TypeConversion throw exception and the scene gets corrupted.

    the only workaround now is to remove number from enum.


    Code (CSharp):
    1. Before:
    2. public enum MovementState
    3.     {
    4.         Idle = 1,
    5.         Run = 2,
    6.         Attack = 3
    7. }
    8.  
    9. After(this works):
    10.      
    11. public enum MovementState
    12.     {
    13.         Idle,
    14.         Run,
    15.         Attack,
    16. }
    17.  
     
    Last edited: Jun 17, 2019
  2. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    251
    Note that your working case is equivalent to:

    Code (CSharp):
    1. public enum MovementState
    2.     {
    3.         Idle = 0,
    4.         Run = 1,
    5.         Attack = 2,
    6. }
    Does it work with these values?