Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by julesbrn · Nov 24, 2017 at 11:43 PM · buildnullscriptable objectnull reference

Scriptable objects has empty inspectors and do not exist in build

I am having problems with scriptable objects in my game. I made a single completely unrelated change at one point and all of the scriptable objects became corrupt. When clicking on the scriptable objects the inspector was completely blank, no fields were listed at all. I ended up deleting the object and recreating it. This happened multiple times before that incident, but I did not realize what happened. This does not always happen when I make changes. I don't know what causes it.


The scriptable objects are also completely absent when I build the game. I added a line of code that checks if the reference to the scriptable object is null or not and it always returns a null reference in the built version. In the editor however, everything works fine. I'm thinking unity is not including my scriptable objects in the built version.


The scriptable objects are items. I followed the inventory system tutorial on unity learn. I copied the inventory and item.cs from the tutorial. I did add some extra variables to the item.cs.

I'm almost certain there is nothing wrong with my code because I run "if (item == null)" on start() of each script that has a reference to an item. This always returns true in the built version, aside from the corruption i mentioned above it works when i run it in the editor. I take advantage of a journal type system in my game to act as a debug log.


Is there something I need to do to handle scriptable objects properly? I need to submit a built version of my game for grading. I currently cannot build a version that includes the scriptable objects.


I don't think there is an issue in my code, but I'll include some of it anyway.

item.cs

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 
 [CreateAssetMenu]
 [Serializable]
 public class Item : ScriptableObject
 {
     public string itemName = "unnamed";
     public Sprite sprite;
     public Mesh mesh;
     public Material mat;
     public string ExamineInfo;
 
 }
 

Inventory.cs (part)

     public bool AddItem(Item itemToAdd)
         {
             if (itemToAdd == null)
             {
                 journal.addLog("itemToAdd was null");
             }
    //...
     }

Pickupinteract.cs (part)

     public class PickupInteract : Interact
     {
         public Item item;
         void Start()
         {
             if (item != null)
             {
                 journal.addLog(this.name + " has item of " + item.name);
             }
             else
             {
                 journal.addLog(this.name + " has a null reference to an item");
             }
         }
     //...
     }

(PickupInteract is the script that is called when an item is to be added to the inventory. It should have a reference to the item that will be added to the inventory.)


Just to clarify, the references to the items are set by dragging the item from the project window to the item field in the script. The items are created by clicking create > item in the project window. Any help is appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by julesbrn · Nov 25, 2017 at 10:38 PM

After doing a lot of searching I fixed it. I'm not sure exactly what fixed it, but here's how I fixed it in case anyone needs to know.

First of all, my item's class name was "Item" and the filename was "item.cs" notice the case difference. I changed that then I set the inspector to debug mode (top right of inspector click the three bars then click debug) then i noticed the script was set to none. I set that to my Item script then deleted all of the .meta files for the items and got it to work.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image urzzusmaatra · Jan 10, 2018 at 08:26 AM 0
Share

Had a same problem.

$$anonymous$$y SciptableObject class was in another file (different names), and i also noticed that script variable is None. After creating new script for my scriptable class the names, i changed manually m_Script variable in serialized objects. Everything went back to normal.

Thank you for posting your solution!

avatar image JustCarty · May 16, 2020 at 07:57 AM 0
Share

For anyone wondering why this hasn't solved it for them. I had the same problem, I thought it was ScriptableObjects, but it was because my properties were written has { get; set; } which wasn't being serialised properly.

avatar image
0

Answer by dbobyla_dodo4story · May 08, 2018 at 12:45 PM

Worked for me.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ZachIsAGardner · Jun 08, 2018 at 11:51 PM

Hi I had a similar problem that got fixed a different way, felt like I should share.

My issue was that I made a change to my ScriptableObject class and old instances of that class now had blank inspectors but new instances worked just fine.


Here's my fix

  1. Create a new instance of your scriptable object

  2. Open the .asset file of your new instance

  3. Copy the guid from the m_Script line

  4. Paste that guid over the guid in the .asset file of the scriptable object instance that stopped working

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mahdiii · Dec 19, 2018 at 08:09 AM

Yes. It is true. Watch your scriptableObject asset. In script section, you may see none. Your classes names and files names must be the same. Change the name and again create the SO. In the editor it is OK but in the build, you get the null reference error.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

if ( Transform == null) ?? Empty Transform reference 1 Answer

Null Reference exception when calling using "script.gameObject.GetComponent 1 Answer

Checking if an object in a 2D array is null triggers a null reference exception 0 Answers

Scriptable Object in Editor vs in Build 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges