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:
---CurrentInventory.cs---
public class CurrentInventory : ScriptableObject
{
[SerializeField]
public List<Item> items;
}
--Item.cs---
[System.Serializable]
public class Item : ICloneable
{
[SerializeField]
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;
[SerializeField]
public List<Connection> connectedObjects = new List<Connection>();
public object Clone() {
return this.MemberwiseClone();
}
}
---Inventory Data(Blueprint of the inventory)---
public class InventoryData : ScriptableObject
{
[SerializeField]
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;
savedItem.connectedObjects.Add(connection);
}
currentInventory.items.Add(savedItem);
runtimeIdx++;
}
---Save/Load Code---
ES3.Save<CurrentInventory>("inventory", currentInventory);
ES3.Load<CurrentInventory>("inventory", currentInventory);
How to save prefab reference in ScriptableObject?
Re: How to save prefab reference in ScriptableObject?
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
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