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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug Loaded ScriptableObject is null but has value when using Fast enter play mode

Discussion in 'Addressables' started by WAYN_Games, May 13, 2021.

  1. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    822
    Hello,

    I'm using scriptable object combined with addressable for my ability system.
    I have been strugulling with an peculiar issue when using the fast "enter play mode" option of the editor.

    I display some information about the ability on screen and some data is not displayed but others are.
    If i have the domain reload option ticked I have no issue but If I don't reload the domain on enter play mode I end up with a null reference on my scriptableobject while it has data.

    upload_2021-5-13_11-39-30.png

    In my code I do some null check on the ability to gard against null pointer but in that case even if the oject is considerd null, I do have all the expected values...

    Fast enter play mode without issue (which is no longer fast enter play mode in that configuration...)
    upload_2021-5-13_11-41-10.png

    upload_2021-5-13_11-43-13.png
     

    Attached Files:

    prgramernoob101 likes this.
  2. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    822
    I have worked around it by making an ugly copy of the ability loaded through addressable to a new instance of the scriptable object.

    Code (CSharp):
    1. public static ScriptableAbility CopyOf(ScriptableAbility original)
    2.     {
    3.         ScriptableAbility copy = new ScriptableAbility();
    4.         copy.Id = original.Id;
    5.         copy.Icon = original.Icon;
    6.         copy.Name = original.Name;
    7.         copy.Range = original.Range;
    8.         copy.Spawnables = original.Spawnables;
    9.         copy.Timings = original.Timings;
    10.         copy.Costs = original.Costs;
    11.         copy.Effects = original.Effects;
    12.         return copy;
    13.     }
    1) it's ugly
    2) it adds maintenance cost
    3) it probably create more GC
     
    prgramernoob101 likes this.
  3. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    822
    In fact, the "Fast enter play mode" does not reload the asset,if I change the icon for instance, it does not update until I reload the domain.
     
    prgramernoob101 likes this.
unityunity