Playmaker Forum

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

Title: Mecanim "Set Animator Look At" can't work in Unity5
Post by: Hayato on April 23, 2015, 11: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, 12:55:18 PM
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, 02:11:04 PM
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 19, 2015, 12:13:54 AM
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 25, 2015, 12:30:13 AM
[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, 04: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, 05: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, 10: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, 08: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, 02:39:18 PM
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, 03: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, 01:03:51 PM
Anyone have any insight?
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: paul.harden on January 13, 2016, 08: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, 11: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, 07:40:56 AM
Bump! :)
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on March 17, 2016, 10: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, 11: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, 09: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, 12:00:10 PM
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, 05: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, 06: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, 06: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, 08: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, 01:21:49 PM
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, 11: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?
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on November 30, 2017, 01:26:46 AM
Hi,

 yes, simply double click on the warning and it will open the script editor, you can then delete the line where you have Debug.Log(...)

 Bye,

 Jean
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: MAX_POWER on November 30, 2017, 10:10:57 AM
Hi,

 yes, simply double click on the warning and it will open the script editor, you can then delete the line where you have Debug.Log(...)

 Bye,

 Jean

Hi, Yes I have looked for that but Debug.Log can not be found anywhere from the SetAnimatorLookAt script.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: djaydino on November 30, 2017, 04:12:50 PM
Hi,
Do you have a 'playmaker animator' in the root of your project or do you have a animator folder inside the palymaker\Actions folder?

I would still suggest to update playmaker as there are many changes and features added since your version.

but copy(Backup) your project and try it out on the copy.
Also read carefully when installing
, you might need to remove some folders when installing (likely the 'playmaker animator' folder) as they are now included with the standard playmaker actions.

If you need any help updating, let me know.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: MAX_POWER on November 30, 2017, 04:32:02 PM
Hi,
Do you have a 'playmaker animator' in the root of your project or do you have a animator folder inside the palymaker\Actions folder?

I would still suggest to update playmaker as there are many changes and features added since your version.

but copy(Backup) your project and try it out on the copy.
Also read carefully when installing
, you might need to remove some folders when installing (likely the 'playmaker animator' folder) as they are now included with the standard playmaker actions.

If you need any help updating, let me know.

Playmaker animator is in the root folder. There's no animator folder under actions folder.

Last time I tried updating playmaker I ran into problems, some things didn't work anymore, it was a few versions back though. I wouldn't want to update playmaker with current project as everything except this error works good with this older version. I'm hoping to finish this project in the next summer so after a few years of development I don't want to run into unexpected bugs now.
Title: Re: Mecanim "Set Animator Look At" can't work in Unity5
Post by: jeanfabre on December 01, 2017, 01:38:29 AM
Hi,

 yes sorry, I looked at the warning and I get it now. Nothing to do with a debug.Log it's Unity itself that throw this.

 Basically, you need to update the actions with the latest ones available on the ecosystem, they fix this issue.

 bye,

Jean