- Home /
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.
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.
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!
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.
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
Create a new instance of your scriptable object
Open the .asset file of your new instance
Copy the guid from the m_Script line
Paste that guid over the guid in the .asset file of the scriptable object instance that stopped working
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.
Your answer
Follow this Question
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