I am creating a CutScene system extension. In this system, the user would describe a cut scene by using a set of pre programmed nodes, in an execution list. The system already works, but I am having this problem that I can’t work out.
When I create any prefab of GameObjects using my custom scripts, they lose the references to all the scriptable objects they should have.
I’m having this trouble for a while, and tried to solve it in many different ways. But none of them work. This is my problem:
I have a MonoBehaviour class called CutScene, and it is as follows:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CutScene : MonoBehaviour {
[HideInInspector]
public GameSwitch gameSwitch;
public List<CutSceneNodes> nodeList = new List<CutSceneNodes>(); //CutSceneNode Class Inherits from the ScriptableObject Class
public bool pauseGame = true;
public CutSceneSystem css;
[HideInInspector]
public int indexOfSwitch = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
The CutScene Class have a property called nodeList, as seen above, which is a List of CutSceneNodes.
The CutSceneNodes class inherits from the ScriptableObject Class.
When a Game Object with the CutScene MonoBehaviour class as a component is dragged from the hierarchy to the project files to create a prefab of that game Object, the resulting prefab loses the reference to the nodeList property and all other references to any ScriptableObjects.
It’s worth mentioning, that the initialisation of the list and its contents, are made in a editor script, which instantiate the CutSceneNodes with the code:
ScriptableObject.CreateInstance<CutSceneNodes>();
The CutSceneNodes class is marked as [Serializable], and all its properties are public.
Thank you ![]()