Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

(Tiny C#) Error loading a scene : IndexOutOfRangeException

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

  1. romiohasan


    Apr 8, 2019
    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/
    Unity.Properties.TransferVisitor`1+TransferValueAction`3[TSourceContainer,TDestinationProperty,TDestinationContainer,TDestinationValue].VisitProperty[TSourceProperty,TSourceValue] (TSourceProperty srcProperty, TSourceContainer& srcContainer, Unity.Properties.ChangeTracker& propertyChangeTracker) (at Library/PackageCache/
    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!


    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. }
    9. After(this works):
    11. public enum MovementState
    12.     {
    13.         Idle,
    14.         Run,
    15.         Attack,
    16. }
    Last edited: Jun 17, 2019
  2. joncham


    Unity Technologies

    Dec 1, 2011
    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?