简体   繁体   English

除非在检查器中更改字段,否则 Animation 无法正确播放

[英]Animation not playing correctly unless field is changed in inspector

I have created a animator to animate my character holding a weapon.我创建了一个动画师来为我的角色手持武器制作动画。 The problem is that the animator does not animate the weapon, but it animates everything else.问题是动画师不会为武器设置动画,但它会为其他所有内容设置动画。 I thought this was because it was being spawned in and didn't exist yet but I tried using Invoke() and IEnumerable to run the method that plays the animation later, but that didn't change anything.我认为这是因为它正在生成并且还不存在,但我尝试使用Invoke()IEnumerable来运行稍后播放 animation 的方法,但这并没有改变任何东西。 I am very frustrated and do not understand what I am doing wrong.我很沮丧,不明白我做错了什么。

Something that is wierd is that if I change any of the Animator properties in the Inspector panel, the animation fixes itself (demonstration: https://imgur.com/a/BqZUI6N )奇怪的是,如果我更改 Inspector 面板中的任何 Animator 属性,animation 会自行修复(演示: https://imgur.com/a/BqZUI6N

How my animator looks like: https://imgur.com/a/HZtBb0c (I have verified and the animation is playing)我的动画师的样子: https://imgur.com/a/HZtBb0c (我已经验证并且 animation 正在播放)

My object hierarchy: https://imgur.com/tvR4deZ (The object that doesn't animate is "Stick", the other objects that do animate are "ref_right_hand_grip" and "ref_left_hand_grip") My object hierarchy: https://imgur.com/tvR4deZ (The object that doesn't animate is "Stick", the other objects that do animate are "ref_right_hand_grip" and "ref_left_hand_grip")

Code that sets the animation:设置 animation 的代码:

GameObject newHolding = null;
if (holding && holding.name != item.data.name)
{
    DestroyImmediate(holding);
    newHolding = Instantiate(item.data.holdingItem, holdingParent.transform, false);
    newHolding.name = item.data.name;
    holding = newHolding;
}
else if (!holding)
{

    newHolding = Instantiate(item.data.holdingItem, holdingParent.transform, false);
    newHolding.name = item.data.name;
    holding = newHolding;
}
anim.Play("equip_" + item.data.id);

EDIT: I did further investigation.编辑:我做了进一步的调查。 The issue is probably something to do with the object being created.该问题可能与正在创建的 object 有关。 When I created the object beforehand and simply enable/disable it when the player selects it, the animation plays correctly.当我事先创建 object 并在玩家选择它时简单地启用/禁用它时,animation 可以正常播放。 I should mention I am using Mirror (Networking)我应该提到我正在使用镜像(网络)

The way I fixed this is by encapsulating the object that was instantiated (stick) in another GameObject, and animed the encapsulator instead.我解决此问题的方法是将 object 封装在另一个 GameObject 中实例化(粘住),然后将封装器动画化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM