Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: Hayato on April 23, 2015, 08:23:37 AM

Title: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Hayato 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)
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: lukew on May 18, 2015, 09:55:18 AM
Bump.

I've just updated Animator Actions to Unity 5 and I'm getting same problem.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre 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
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Hayato 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.
(http://i.imgur.com/dxWCJAk.png)
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Hayato 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;
}
}
}
}

Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on May 25, 2015, 01:08:31 AM
Hi,

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

 Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on June 03, 2015, 02:04:39 AM
Hi,

 This is done (https://twitter.com/JeanAtPlayMaker/status/606020543939276800). let me know how it goes. (it's available on the ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) as well)

 Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Kemono 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.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on August 27, 2015, 05:47:06 AM
Hi,

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

Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Pandur 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
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: EricColossal 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.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: EricColossal on October 29, 2015, 10:03:51 AM
Anyone have any insight?
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: paul.harden 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?
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre 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
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Kubold on March 16, 2016, 04:40:56 AM
Bump! :)
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on March 17, 2016, 07:08:37 AM
Hi,

 it's already tomorrow :)... :o

oups bad submition of post... reply pending coming soon :)

Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: tankun on December 02, 2016, 09:00:52 AM
Hi,

Any news or updates on this topic?

Look At still doesn't work. Even with the updated PlayMakerAnimatorIKProxy.

Thanks
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on December 05, 2016, 07:09:38 AM
Hi,

 Odd, what doesn't work? do you get a warning in the Unity console or it's not following the target?

 Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: tankun on August 14, 2017, 09:00:10 AM
Hi,

SetAnimatorLookAt is still not working with Unity 2017.1p2 even with the animator proxy.

Playmaker version is 1.8.5

It's not giving any errors, it's just not working.

Thanks

Tan
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on August 15, 2017, 02:06:26 AM
Hi,

 It can't find any issues with this. It works fine on 2017 as well.

(https://dl.dropboxusercontent.com/u/17356625/Unity/PlayMaker/MecanimIK.gif)

Not trying to escape the issue, but I need to be able to repro this before I can find what's wrong. Can you maybe boil down the issue to its minimum, and package it and send it over to me ( via pm if you don't want to share this publicly), and I'll have a look.

 Bye,

 Jean

 
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: LordHorusNL on August 16, 2017, 03:06:58 AM
I noticed that "Set Animator Look At" only works when running in a FSM that is actually on the game object with the animator component!

So it will not work when running it from a FSM on a child or on a different game object, this severely limits this actions usability unfortunately.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on August 16, 2017, 03:26:33 AM
Hi,

 Yes, that's a limitation unfortunatly. The current beta is addressing this, so the next version of PlayMaker will be more flexible on that front, including triggers and colliders.

 Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: LordHorusNL on August 16, 2017, 05:27:35 AM
Thats great to hear jean, that will definitely be very helpfull. :)
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: MAX_POWER on November 10, 2017, 11:21:49 AM
Is there a way to fix this with Unity 5.3.4 and Playmaker 1.8.0f43? Currently I don't want to update unity or playmaker with this project that I have.

The Animator IK Proxy is on another object than the one that drives the Set Animator Look At. The biggest problem is that it causes fps lag because of the warning LogStringToConsole that is constanlty flooding. Any way to fix this editing the playmaker action scripts or? Thanks
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: MAX_POWER on November 13, 2017, 09:07:21 AM
I forgot to mention that the Animator Look At works just fine even though it's not in the same object but the warning it causes constantly is the problem because it causes framerate drop. Any way to edit the script to get rid of the warning?