playMaker

Author Topic: Please improve GameObjectCompare action  (Read 2230 times)

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Please improve GameObjectCompare action
« on: December 26, 2018, 03:47:22 AM »
GameObjectCompare action has the compareTo as a [RequiredField]
looks like this:

Code: [Select]
...
[RequiredField]
[Tooltip("Compare the variable with this Game Object")]
public FsmGameObject compareTo;
...

If I simply comment out this line like so:

Code: [Select]
...
//[RequiredField]  commented out line
[Tooltip("Compare the variable with this Game Object")]
public FsmGameObject compareTo;
...

The action becomes much more useful as now you are also able to compare your game object variable to "none", which opens up the possibilities of the action usage.

Of course I can make this modification myself, but every time I update playmaker or start a new project I have to do this again.
Please add this improvement to the official action.

Br,
szomaza

The original , unmodified GameObjectCompare action:
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Compares 2 Game Objects and sends Events based on the result.")]
public class GameObjectCompare : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Title("Game Object")]
[Tooltip("A Game Object variable to compare.")]
public FsmOwnerDefault gameObjectVariable;

[RequiredField]
[Tooltip("Compare the variable with this Game Object")]
public FsmGameObject compareTo;

[Tooltip("Send this event if Game Objects are equal")]
public FsmEvent equalEvent;

[Tooltip("Send this event if Game Objects are not equal")]
public FsmEvent notEqualEvent;

[UIHint(UIHint.Variable)]
[Tooltip("Store the result of the check in a Bool Variable. (True if equal, false if not equal).")]
public FsmBool storeResult;

[Tooltip("Repeat every frame. Useful if you're waiting for a true or false result.")]
public bool everyFrame;

public override void Reset()
{
gameObjectVariable = null;
compareTo = null;
equalEvent = null;
notEqualEvent = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoGameObjectCompare();

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

public override void OnUpdate()
{
DoGameObjectCompare();
}

void DoGameObjectCompare()
{
var equal = Fsm.GetOwnerDefaultTarget(gameObjectVariable) == compareTo.Value;

storeResult.Value = equal;

if (equal && equalEvent != null)
{
Fsm.Event(equalEvent);
}
else if (!equal && notEqualEvent != null)
{
Fsm.Event(notEqualEvent);
}

}

}
}

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Please improve GameObjectCompare action
« Reply #1 on: December 26, 2018, 01:41:32 PM »
It does, for me, already work like that. Just leave the game object to none(not 'none' variable, but None(Game Object)).
You also have an action called "game object is null" if you want to use that instead.

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: Please improve GameObjectCompare action
« Reply #2 on: December 27, 2018, 01:04:06 PM »
Nope!
If the [RequiredField] line is not commented out for the "compareTo" then no matter if you set it to:
- None, or to
- None (Game Object)
The field will be red and there will be an error.

If it is not red for you then I believe you must have the [RequiredField] commented out for that parameter.

Thanks for the Game Object Is Null action idea.
That will also work perfectly in this same situation and might even be faster.

Br,
szomaza
« Last Edit: December 27, 2018, 01:09:45 PM by szomaza »

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Please improve GameObjectCompare action
« Reply #3 on: December 27, 2018, 03:41:52 PM »
Nope? Yep!

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: Please improve GameObjectCompare action
« Reply #4 on: December 28, 2018, 08:47:33 AM »
 :D
Then can somebody explain why the same script behaves in two different ways?

If I comment out that one line then it behaves like DanielThomas is showing but he does not need to comment it out.
What is going on?  :D

Code: [Select]
[RequiredField]
[Tooltip("Compare the variable with this Game Object")]
public FsmGameObject compareTo;

like so:

//[RequiredField]
[Tooltip("Compare the variable with this Game Object")]
public FsmGameObject compareTo;


« Last Edit: December 28, 2018, 08:50:53 AM by szomaza »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Please improve GameObjectCompare action
« Reply #5 on: January 10, 2019, 03:20:15 AM »
Hi,

 you don't exactly have the same setup, he has a gameobject variable pointing to no gameobjects

simply use GameObjectIsNull action, this is the action intended to be used if you want to check against null, else if you want to compare, you obviously want to compare at least with one variable against a known object, or two variables.

Bye,

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: Please improve GameObjectCompare action
« Reply #6 on: January 19, 2019, 04:30:46 AM »
Thank you very much. I'll be using GameObjectIsNull in such cases.

I also noticed what was the difference between our setups: The reason he does not see the error of the RequiredField being red, is because his scene is running.