Egret社区
10银子
本帖最后由 瓦哥 于 2019-3-15 11:24 编辑

游戏开发中使用骨骼做角色动画,战斗结束后销毁资源下次重进再创建,销毁后有概率出现错误
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.
DragonBones.UnitySlot._UpdateTransform (Boolean isSkinnedMesh) (at Assets/DragonBonesCSharp-master/Unity/src/DragonBones/Scripts/unity/UnitySlot.cs:836)
DragonBones.Slot.Update (Int32 cacheFrameIndex) (at Assets/DragonBonesCSharp-master/DragonBones/src/DragonBones/armature/Slot.cs:855)
DragonBones.Armature.AdvanceTime (Single passedTime) (at Assets/DragonBonesCSharp-master/DragonBones/src/DragonBones/armature/Armature.cs:428)
DragonBones.WorldClock.AdvanceTime (Single passedTime) (at Assets/DragonBonesCSharp-master/DragonBones/src/DragonBones/animation/WorldClock.cs:154)
DragonBones.DragonBones.AdvanceTime (Single passedTime) (at Assets/DragonBonesCSharp-master/DragonBones/src/DragonBones/core/DragonBones.cs:334)
DragonBones.ClockHandler.Update () (at Assets/DragonBonesCSharp-master/Unity/src/DragonBones/Scripts/unity/UnityFactory.cs:37)


UnitySlot 文件836行 _renderDisplay 报错了。我在这个函数 UnitySlot ._UpdateTransform() 开头加一句 if (_renderDisplay == null) return; 就正常了。
我在Lua 中销毁的方法

function ViewBattleRole:destroy()
    self.role.armature:RemoveEventListener(DragonBones.EventObject.FRAME_EVENT, self.CallBack);
    self.role = nil;

    local uac = self.RoleSP:GetComponent("UnityArmatureComponent");
    DragonBones.UnityFactory.factory._dragonBones.clock:Remove(uac.armature);
    uac.armature.animation:Stop();
    uac.armature: Dispose();
    uac: Dispose();

    if self.RoleSP ~= nil then
        destroy(self.RoleSP.gameObject);
        self.RoleSP = nil;
    end
end



按网上说的方法加了中间那段,加不加效果一样。有没有哪位大佬遇到过这方面的问题,不吝赐教。谢谢!

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

瓦哥

初学乍练

积分: 2 帖子: 2 精华: 0

楼主热帖

小黑屋|京网文[2014]0791-191号|京ICP证150115号|Egret社区 ( 京ICP备14025619号

Powered by Discuz! X3.2 © 2001-2019 Comsenz Inc.

返回顶部