PlayMaker Help & Tips > PlayMaker Help

Mecanim "Set Animator Look At" can't work in Unity5

(1/6) > >>

Hayato:
Hello I'm using  Mecanim Animator actions in unity 5 and find the "Set Animator Look At" Action can't work.
It got warning massage below:


--- Code: ---Setting and getting IK Goals should only be done in OnAnimatorIK or OnStateIK
UnityEngine.Animator:GetIKRotation(AvatarIKGoal)
HutongGames.PlayMaker.Actions.GetAnimatorIKGoal:DoGetIKGoal() (at Assets/PlayMaker Animator/Actions/GetAnimatorIKGoal.cs:109)
HutongGames.PlayMaker.Actions.GetAnimatorIKGoal:OnUpdate() (at Assets/PlayMaker Animator/Actions/GetAnimatorIKGoal.cs:95)
HutongGames.PlayMaker.FsmState:OnUpdate()
HutongGames.PlayMaker.Fsm:UpdateState(FsmState)
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

--- End code ---

The Animator IK Proxy has added and other IK actions like "SetAnimatorIKGoal" can work well.
How can I fix it ?

*Using playmaker 1.7.8.3  and Unity 5.0.0 Mecanim Actions in Unity 5.0.1f1 (https://hutonggames.fogbugz.com/default.asp?W1031)

lukew:
Bump.

I've just updated Animator Actions to Unity 5 and I'm getting same problem.

jeanfabre:
Hi,

It's ok, this works anyway. You can ignore this warning.

 It's because you need to drop the IKAnimator proxy, the action detects it automatically. I'll update this so that it's more obvious. I'll push a sample on the ecosystem.

 Bye,

 Jean

Hayato:
Thank you for reply my question.
I have drop the PlayMakerAnimatorIKProxy component into the humanoid charactor.
And can see the "Set Animator IK Goal" work well.
But the "Set Animator Look At" seem didn't work at the same charactor.
Do I miss anything or just use the action in a wrong way ?

I take a screenshot for it.

Hayato:
[Solved!]

I compare the "SetAnimatorIKGoal.cs" and "SetAnimatorLookAt.cs" files.
And found that SetAnimatorIKGoal have change to use "PlayMakerAnimatorIKProxy" component ,but SetAnimatorLookAt Action still use a old "PlayMakerAnimatorMoveProxy" component .
So I try to exchange some words in SetAnimatorLookAt.cs base on the SetAnimatorIKGoal.cs , somthing like :

--- Code: ---PlayMakerAnimatorMoveProxy --> PlayMakerAnimatorIKProxy
--- End code ---
and

--- Code: ---public void OnAnimatorMoveEvent() --> public void OnAnimatorIKEvent(int layer)
--- End code ---

Finally it works well now :)

The modified "SetAnimatorLookAt.cs" as below :

--- Code: ---// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Animator")]
[Tooltip("Sets look at position and weights. A GameObject can be set to control the look at position, or it can be manually expressed.")]
[HelpUrl("https://hutonggames.fogbugz.com/default.asp?W1071")]
public class SetAnimatorLookAt: FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animator))]
[CheckForComponent(typeof(PlayMakerAnimatorIKProxy))]
[Tooltip("The target. An Animator component and a PlayMakerAnimatorIKProxy component are required")]
public FsmOwnerDefault gameObject;

[Tooltip("The gameObject to look at")]
public FsmGameObject target;

[Tooltip("The lookat position. If Target GameObject set, targetPosition is used as an offset from Target")]
public FsmVector3 targetPosition;

[HasFloatSlider(0f,1f)]
[Tooltip("The global weight of the LookAt, multiplier for other parameters. Range from 0 to 1")]
public FsmFloat weight;

[HasFloatSlider(0f,1f)]
[Tooltip("determines how much the body is involved in the LookAt. Range from 0 to 1")]
public FsmFloat bodyWeight;

[HasFloatSlider(0f,1f)]
[Tooltip("determines how much the head is involved in the LookAt. Range from 0 to 1")]
public FsmFloat headWeight;

[HasFloatSlider(0f,1f)]
[Tooltip("determines how much the eyes are involved in the LookAt. Range from 0 to 1")]
public FsmFloat eyesWeight;

[HasFloatSlider(0f,1f)]
[Tooltip("0.0 means the character is completely unrestrained in motion, 1.0 means he's completely clamped (look at becomes impossible), and 0.5 means he'll be able to move on half of the possible range (180 degrees).")]
public FsmFloat clampWeight;

[Tooltip("Repeat every frame. Useful for changing over time.")]
public bool everyFrame;

private PlayMakerAnimatorIKProxy _animatorProxy;

private Animator _animator;

private Transform _transform;

public override void Reset()
{
gameObject = null;
target = null;
targetPosition = new FsmVector3() {UseVariable=true};
weight = 1f;
bodyWeight = 0.3f;
headWeight = 0.6f;
eyesWeight = 1f;
clampWeight = 0.5f;

everyFrame = false;
}

public override void OnEnter()
{
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);

if (go==null)
{
Finish();
return;
}

_animator = go.GetComponent<Animator>();

if (_animator==null)
{
Finish();
return;
}

_animatorProxy = go.GetComponent<PlayMakerAnimatorIKProxy>();
if (_animatorProxy!=null)
{
_animatorProxy.OnAnimatorIKEvent += OnAnimatorIKEvent;
}else{
Debug.LogWarning("This action requires a PlayMakerAnimatorIKProxy. It may not perform properly if not present.");
}



GameObject _target = target.Value;
if (_target!=null)
{
_transform = _target.transform;
}


DoSetLookAt();

if (!everyFrame)
{
Finish();
}
}

public void OnAnimatorIKEvent(int layer)
{
if (_animatorProxy!=null)
{
DoSetLookAt();
}
}

public override void OnUpdate()
{
if (_animatorProxy==null)
{
DoSetLookAt();
}
}


void DoSetLookAt()
{
if (_animator==null)
{
return;
}

if (_transform!=null)
{
if (targetPosition.IsNone)
{
_animator.SetLookAtPosition(_transform.position);
}else{
_animator.SetLookAtPosition(_transform.position+targetPosition.Value);
}
}else{

if (!targetPosition.IsNone)
{
_animator.SetLookAtPosition(targetPosition.Value);
}
}


if (!clampWeight.IsNone)
{
_animator.SetLookAtWeight(weight.Value,bodyWeight.Value,headWeight.Value,eyesWeight.Value,clampWeight.Value);
}else if (!eyesWeight.IsNone)
{
_animator.SetLookAtWeight(weight.Value,bodyWeight.Value,headWeight.Value,eyesWeight.Value);
}else if (!headWeight.IsNone)
{
_animator.SetLookAtWeight(weight.Value,bodyWeight.Value,headWeight.Value);
}else if (!bodyWeight.IsNone)
{
_animator.SetLookAtWeight(weight.Value,bodyWeight.Value);
}else if (!weight.IsNone)
{
_animator.SetLookAtWeight(weight.Value);
}


}

public override void OnExit()
{
if (_animatorProxy!=null)
{
_animatorProxy.OnAnimatorIKEvent -= OnAnimatorIKEvent;
}
}
}
}

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version