因此,我正在为我的应用程序开发一个保存系统,并试图将对象存储在一个GameObject数组中,如下所示:
public GameObject[ ] entriesInScene;
当我将GameObject存储在数组中时,它会存储GameObject ID。当我尝试在后面的代码中实例化对象时,请使用以下if循环:
foreach (GameObject go in saveObject.entriesInScene)
{
Debug.Log(go);
GameObject entry = Instantiate(go, position, Quaternion.identity);
entry.transform.SetParent(null);
entry.transform.SetParent(scroll.transform);
entry.transform.localScale = new Vector3(1,1,1);
}它给了我一个MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.的错误
有人知道如何修复这个问题吗?还是知道如何从ID中获取GameObject以使实例化工作?
发布于 2022-01-01 08:18:09
据我所知,通过统一,您将无法通过序列化直接保存整个GameObjects。对于实现保存系统的类似问题,我的方法是将每个对象类型存储为一个预制件,然后将重要值本身保存在脚本中(例如用户可以放置的微波炉预制件,但我会将Vector3存储到这个位置)。在大多数情况下,您应该能够只存储在预制件实例之间更改的值。
https://stackoverflow.com/questions/70535176
复制相似问题