【问题标题】:Unity | MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it团结 | MissingReferenceException:“Transform”类型的对象已被破坏,但您仍在尝试访问它
【发布时间】:2014-11-11 22:40:47
【问题描述】:

MissingReferenceException:“Transform”类型的对象已被销毁,但您仍在尝试访问它。

您的脚本应该检查它是否为空,或者您不应该销毁该对象。

UnityEngine.Transform.get_position () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineTransform.cs:28)

Destroy+$SpawnAfter5Seconds$1+$.MoveNext () (at Assets/Scripts/Destroy.js:22)

有什么帮助吗?

【问题讨论】:

  • 您正在破坏对象引用,而不是实例化的引用。实例化一个变量来保存对象并销毁它。

标签: unity3d


【解决方案1】:

您要对现在为null 的对象执行操作,因为它是Destroyed

解决方案

不要破坏它或不要尝试访问已经被破坏的东西。你总是可以这样检查:

if(transformReference != null)
{
    // Safe to use. 
}

【讨论】:

  • 但我没有销毁它
【解决方案2】:

这意味着你试图移动、改变位置等的对象被破坏了。 尝试创建一个新对象,该对象的名称类似于您在脚本中使用的对象。如果没有帮助,请在评论中发布脚本。 祝你有美好的一天!

【讨论】:

    【解决方案3】:
    void FixedUpdate()
    {
        Vector3 targetCamePos = target.position + offset;
        if (targetCamePos != null)
        {
            transform.position = Vector3.Lerp(transform.position, targetCamePos, smoothing * Time.deltaTime);
            if (transform.position.y < lowY)
            {
                transform.position = new Vector3(transform.position.x, lowY, 
    transform.position.z);
    
                //if our character fallow the x/z not y
            }
        }  
    }
    

    【讨论】:

    • 请帮忙,因为由于某种原因我无法弄清楚为什么转换给我一个错误
    • 你应该提供更多的描述来回答
    猜你喜欢
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多