playMaker

Author Topic: 'Activate by tag' action not working properly  (Read 8457 times)

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
'Activate by tag' action not working properly
« on: April 26, 2015, 06:23:53 PM »
I am using the 'activate by tag' action.  It seems to turn stuff off but not on.  Weird.  Included are 2 pictures showing the actions.  One is on and 1 is off.  Once looped though, the off works while the on does not.  This was working before upgrading to unity 5.

Now It may be a programming error, however I'm 90% sure it is not.  Could someone look at the C# part of the action and verify it is correct.  It might be something simple.  I have found errors in other actions before so it's possible.

I do have 2 loops where as loop 1 is keyboard and loop 2 is mouse.  they are independent and the error is on both of them.  I have verified that the loop is going though correctly and the only activate/deactive is what is shown.
« Last Edit: April 26, 2015, 06:26:19 PM by wheretheidivides »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: 'Activate by tag' action not working properly
« Reply #1 on: April 26, 2015, 07:28:19 PM »
Here is script.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
// original action by Graham: http://hutonggames.com/playmakerforum/index.php?topic=9547.msg45318#msg45318
/*--- __ECO__ __ACTION__ ---*/

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Activates or deactivates all Game Objects with a given tag.")]
public class ActivateObjectsByTag : FsmStateAction
{
[RequiredField]
[Tooltip("The tag to filter objects to activate/deactivate")]
[UIHint(UIHint.Tag)]
public FsmString tag;

[RequiredField]
        [Tooltip("Check to activate, uncheck to deactivate Game Object.")]
        public FsmBool activate;

[Tooltip("Resets the affected game objects when exiting this state to their original activate state. Useful if you want an object to be controlled only while this state is active.")]
public FsmBool resetOnExit;

bool[] _activeStates;
GameObject[] _gos;

public override void Reset()
{
activate = false;
tag = null;
resetOnExit = false;
}

public override void OnEnter()
{
_gos = GameObject.FindGameObjectsWithTag(tag.Value);
_activeStates = new bool[_gos.Length];

int i= 0;
        foreach (GameObject go in _gos)
{

#if UNITY_3_5 || UNITY_3_4
_activeStates[i] = go.active;
                go.active = activate.Value;
#else
_activeStates[i] = go.activeSelf;
    go.SetActive(activate.Value);
#endif

i++;
        }

Finish();
}

public override void OnExit()
{
if( resetOnExit.Value && _gos!=null)
{
int i= 0;
        foreach (GameObject go in _gos)
{

#if UNITY_3_5 || UNITY_3_4
                go.active = _activeStates[i];
#else
    go.SetActive(_activeStates[i]);
#endif

i++;
        }
}
}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: 'Activate by tag' action not working properly
« Reply #2 on: April 27, 2015, 03:30:10 AM »
Hi,
 
yep, that action can not work properly unfortunatly. It's a Unity restriction:

http://stackoverflow.com/questions/16168596/find-inactive-gameobject-by-tag-in-unity3d

The solution is to use ArrayMaker and store the objects you want to activate by tag, so that they can be deactivate, you'll still have their references in the array.

then you use the arrayMaker action : ArrayListFindGameObjectsByTag

I have pushed a new version of ArrayMaker featuring a new action:

ArrayListActivateGameObjects, so now you'll be able to achieve activation of deactivated GameObjects.

 I also removed the "activate by tag" from the ecosystem, as it clearly isn't working as it should.


Thanks for spotting this :)


Bye,

 Jean
« Last Edit: April 27, 2015, 03:40:48 AM by jeanfabre »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: 'Activate by tag' action not working properly
« Reply #3 on: April 27, 2015, 11:20:39 AM »
I'm having the same issue doing it this way.  Any ideas other than arrays?
- find game object (store into GO variable)
- activate/deactivate GO variable


Before, I had the objects in the scene and I could reference them directly.  Now I have most of them stored as prefabs.  So in the menu, the user can turn the snow on or off.

I suppose I could instantiate an object, store it into a global variable ( I know you hate them) and them later activate or deactivate the global variable.
« Last Edit: April 27, 2015, 11:33:13 AM by wheretheidivides »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: 'Activate by tag' action not working properly
« Reply #4 on: April 28, 2015, 03:52:37 AM »
Hi,

 I tested it and it works. what issue do you have? do you get the array list filled up with the Gameobjects to begin with when you use ArrayListFindGameObjectsByTag?

 Bye,

 Jean

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: 'Activate by tag' action not working properly
« Reply #5 on: April 28, 2015, 11:26:20 AM »
I don't mean the array but find a game object that is turned off.  It can't find it with this other action.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: 'Activate by tag' action not working properly
« Reply #6 on: April 28, 2015, 12:11:30 PM »
Hi,

 This is not possible, unless before it's disable you store a reference of this gameobject either in an FsmGameObject or in an ArrayList. No way around it, it's a unity restriction.

 Bye,

 Jean

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: 'Activate by tag' action not working properly
« Reply #7 on: April 28, 2015, 02:16:47 PM »
Once I figured this out (which BTW is NOT in the instructions for the actions), I came up with a work around. 

- Create object
- Active everything recursively
- Look for name of child object
- Store the object in a global variable (which you all hate)
- Turn off child object

Then whenever I need to turn it on or off, I just use the global variable.  It points to the game object which may be off.  It's basically what you said.  The important thing I found out is after creating a object, activate it recursively.  Some of the game objects may be off so you can't find them.  Then with another variable that says if it is on or off (like a bool "SnowOnOff") you set it on or off.
« Last Edit: April 28, 2015, 02:19:52 PM by wheretheidivides »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: 'Activate by tag' action not working properly
« Reply #8 on: April 29, 2015, 07:31:51 AM »
Hi,

 yep, we all fall for this trap. I think it should find disabled GameObject. in editor we can, we simply mention that in the method to inclide or not disabled gameObject, I don't understand why this is not the same at runtime.

Anyway, I am glad you found a way out of this.

 Bye,

 Jean