How to save prefab reference in ScriptableObject?

Discussion and help for Easy Save 3
Post Reply
Posts: 1
Joined: Mon Sep 14, 2020 7:13 am

How to save prefab reference in ScriptableObject?

Post by kendemu »

Hello, I am making a sandbox game.
I am trying to save primitive shapes prefab in a ScriptableObject, but the prefab reference is linked to an empty object when loading. The other values(Vector3/List) are loaded properly. The ScriptableObject prefab reference works in runtime, but it becomes an empty object when loading.

Settings : JSON, load by reference, scene manager enabled, ES3prefab enabled(CubeParts which I want to load)

Here's the code chunks:

public class CurrentInventory : ScriptableObject
public List<Item> items;

public class Item : ICloneable
public int objectID;
public string objectName;
public GameObject prefab;
public Sprite snapshot;
public float mass;
public Color color;
public Vector3 position;
public Quaternion rotation;
public int runtimeIdx;
public List<Connection> connectedObjects = new List<Connection>();

public object Clone() {
return this.MemberwiseClone();
---Inventory Data(Blueprint of the inventory)---
public class InventoryData : ScriptableObject

public List<Item> items = new List<Item>();

---Adding Inventory---
void SaveItems() {
Item savedItem = (Item)inventoryData.items[itemObjectID].Clone();
savedItem.position = currentItem.transform.position;
savedItem.rotation = currentItem.transform.rotation;
savedItem.runtimeIdx = runtimeIdx;
sourceSnap.runtimeIdx = runtimeIdx;
if (isSnap)
savedItem.connectedObjects = new List<Connection>();
Connection connection = (Connection)new Connection().Clone();
connection.idx = targetSnap.runtimeIdx;
connection.position = targetSnap.snapPoints[targetIdx].transform.position;

---Save/Load Code---
ES3.Save<CurrentInventory>("inventory", currentInventory);
ES3.Load<CurrentInventory>("inventory", currentInventory);

User avatar
Moodkie Staff
Posts: 2971
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to save prefab reference in ScriptableObject?

Post by Joel »

Hi there, and thanks for getting in contact.

It's not possible for me to tell what is happening from what you've sent me. Please could you create a new project with a basic scene which replicates your issue and private message it to me?

All the best,
Joel @ Moodkie Interactive
Twitter - Unity

Post Reply