playMaker

Author Topic: Mecanim "Set Animator Look At" can't work in Unity5  (Read 7273 times)

Hayato

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Mecanim "Set Animator Look At" can't work in Unity5
« on: April 23, 2015, 08:23:37 AM »
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: [Select]
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()

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

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #1 on: May 18, 2015, 09:55:18 AM »
Bump.

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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #2 on: May 18, 2015, 11:11:04 AM »
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

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #3 on: May 18, 2015, 09:13:54 PM »
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

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #4 on: May 24, 2015, 09:30:13 PM »
[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: [Select]
PlayMakerAnimatorMoveProxy --> PlayMakerAnimatorIKProxyand
Code: [Select]
public void OnAnimatorMoveEvent() --> public void OnAnimatorIKEvent(int layer)
Finally it works well now :)

The modified "SetAnimatorLookAt.cs" as below :
Code: [Select]
// (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;
}
}
}
}

« Last Edit: May 25, 2015, 07:37:38 PM by Hayato »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #5 on: May 25, 2015, 01:08:31 AM »
Hi,

 thanks, I'll implement the changes in the package.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #6 on: June 03, 2015, 02:04:39 AM »
Hi,

 This is done. let me know how it goes. (it's available on the ecosystem as well)

 Bye,

 Jean

Kemono

  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #7 on: August 22, 2015, 07:21:08 PM »
Did you get a chance to update it in the ecosystem?

I just had this problem and I could not get it to work even with updated ecosystem/playmaker.

However, I copied Hayato's code and wrote over the "SetAnimatorLookAt" script,
and now it works.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #8 on: August 27, 2015, 05:47:06 AM »
Hi,

 uhm... that should be the same. I'll double check.

Bye,

 Jean

Pandur

  • Junior Playmaker
  • **
  • Posts: 82
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #9 on: October 12, 2015, 11:39:18 AM »
at time i became this error :

Code: [Select]
Setting and getting IK Goals should only be done in OnAnimatorIK or OnStateIK
UnityEngine.Animator:SetIKRotationWeight(AvatarIKGoal, Single)
HutongGames.PlayMaker.Actions.SetAnimatorIKGoal:DoSetIKGoal() (at Assets/PlayMaker Animator/Actions/SetAnimatorIKGoal.cs:162)
HutongGames.PlayMaker.Actions.SetAnimatorIKGoal:OnEnter() (at Assets/PlayMaker Animator/Actions/SetAnimatorIKGoal.cs:96)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:UpdateStateChanges()
HutongGames.PlayMaker.Fsm:UpdateState(FsmState)
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

have use update and so one,its work with no problems but 236 error is to mutch :D

EricColossal

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #10 on: October 24, 2015, 12:41:08 PM »
I'm having the same problem as the original poster. All fresh installs of Unity, Playmaker and Animator actions from Ecosystem. I tried copying the code from this thread but that also did not seem to work.

EricColossal

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #11 on: October 29, 2015, 10:03:51 AM »
Anyone have any insight?

paul.harden

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #12 on: January 13, 2016, 06:34:12 AM »
Same problem here, using Unity 5.3.1 and last package from the ecosystem.
However ecosystem package seems to be marked for Unity 4 and it's name is "Animator Proxy". I would have expected it to be "Playmaker Animator".
Versioninfo is {"Major":1, "Patch":2, "Build":0, "Type":"f", "Minor":1}.

Is it the right package?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #13 on: January 13, 2016, 09:34:18 AM »
Hi,

 I'll have a look tomorow morning. I may have missed something for that Unity version.

Bye,

 Jean

Kubold

  • Junior Playmaker
  • **
  • Posts: 99
    • View Profile
Re: Mecanim "Set Animator Look At" can't work in Unity5
« Reply #14 on: March 16, 2016, 04:40:56 AM »
Bump! :)