Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Issues with scriptable objects on b13.

Discussion in '2018.1 Beta' started by georgeq, Apr 17, 2018.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    My game runs fine on the Editor but it generates the following error on the player:

    NullReferenceException: Object reference not set to an instance of an object

    The reference is a scriptable object which has been correctly assigned on the inspector, but also I discovered one issue on the editor; you can assign the reference by dragging and dropping the asset in to the input field, but you won't find it if you look for it with the selection circle.

    scrip.png

    This is a minor issue, however the mayor problem is that this reference is not being transferred to the PC build, that's why I'm getting the error message.

    I have this piece of code:

    Code (CSharp):
    1.  
    2.  
    3.       private void OnCollisionEnter(Collision collision) {
    4.  
    5.          if(HitEvent==null) {
    6.             Debug.Log(Trans.name);
    7.          }
    8.          .
    9.          .
    10.          .
    11.    }

    And what I get on log file is this:

    tankG2018b (3)
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    Casablanca.Tank:OnCollisionEnter(Collision) (at C:\usr\dev\Unity\Juegos\2018\A6\Assets\Casablanca\Scripts\Runtime\Tank.cs:165)

    tankG2018b (2)
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    Casablanca.Tank:OnCollisionEnter(Collision) (at C:\usr\dev\Unity\Juegos\2018\A6\Assets\Casablanca\Scripts\Runtime\Tank.cs:165)

    But as you can see on the screenshot above, in both cases there's a valid reference.
     
  2. tswierkot

    tswierkot

    Joined:
    Feb 15, 2017
    Posts:
    25
    Have you tried deleting your Library and reimporting these assets?
     
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Could you please submit a bug report with a minimal reproduction project for this issue?
     
  4. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Case 1027329.... I forgot to save the scene before sending the bug report, don't know if the report was generated with the saved scene or with the scene in memory, just in case, make sure tankG2018b has an AudioSource attached before testing.
     
    LeonhardP likes this.
  5. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    To work around this problem I decided to load the asset at run time, so I added this code:

    Code (CSharp):
    1.   private void Awake() {
    2.          HitEvent = Resources.Load<AudioEvent>("Hit");
    3.          if(HitEvent==null) {
    4.             Debug.Log("Not loaded");
    5.          }
    6.       }

    Again, on play mode inside the editor I don't get any message on the console, however on the PC player I get this:

    Not loaded
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)

    Scritable objects are completely broken on 2018.1, at least for PC builds.
     
  6. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Same problem with 2018.2.01b
     
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm using scriptable objects all over and no issues with builds, assuming a lot of others are also. So it has to be something specific here it's not a general issue with scriptable objects.

    Would help to see the class holding these references. This sounds a lot like your scriptable object is referenced from a class not that's not marked as Serializable. In which case it looks fine in the editor until you either quit/start unity again or try to make a build.
     
  8. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  9. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Thank you!