playMaker

Author Topic: Activate/Dectivate by Tag  (Read 4512 times)

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Activate/Dectivate by Tag
« on: February 12, 2015, 09:58:54 PM »
I'd like to be able to activate or de-activate something based off of a tag.  That way one could instantiate and destroy things at will.  Later, maybe he could disable something that the remaining bad guys have.

For example:  Let's say you have bad guys that appear every so often and the player gets an ability.  Then all of the bad guys could no longer have weapons.  The activate by tag would deactivate all of the weapons for any bad guy in the scene.  this would be a little different than 'destroy objects by tag' action recently done as that destroys the whole object.  This would just activate or deactivate the object so it doesn't have to be the parent.

Would be really usefull.

Graham

  • Sr. Member
  • ****
  • Posts: 333
  • I Love Playmaker!
    • Portfolio
Re: Activate/Dectivate by Tag
« Reply #1 on: February 14, 2015, 02:10:32 AM »
I attached a simple action to deactivate all game objects with a given tag. Unfortunately I don't think you can search for tags of deactivated objects, so it will not work the other way around for activation.

An alternative would be to use arraymaker. Use the "Array List Find Game Objects By Tag action to fill an array with all of your tagged objects, then use "Array List Get Next" to iterate through and deactivate them with the "Activate Game Object" action. Since you still have them stored in the array you can then cycle through them again but this time reactivating them when needed.
More templates on the Unity Asset Store!

Disclosure: We are using affiliate links to our assets; we may receive a commission for purchases made through them. This helps us to continue developing and maintaining great products!

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Re: Activate/Dectivate by Tag
« Reply #2 on: February 14, 2015, 03:59:27 PM »
So if I add that to a fsm that deals with picking up and dropping objects (like a bolder for example) it would drop down regardless? Because I do have a object that can be picked up with a tag.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Activate/Dectivate by Tag
« Reply #3 on: February 14, 2015, 06:05:30 PM »
Really cool.  this is why playmaker's forems are great and unity's forems suck.  On the unity forems they have attitudes, but here it's a community of cool people.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Activate/Dectivate by Tag
« Reply #4 on: March 05, 2015, 02:42:13 AM »
Hi,
 
Thanks for this action Graham,

 Pushed it on the Ecosystem, I improved it so that you can activate or deactivate, and you can also resetOnExit.


I removed my version from the ecosystem, as I wrongly assumed we could do a generic activate/deactivate action in one go, sorry about that. The solution for a proper activation/deactivation mechanism is to store the gameObjects in a list first, using ArrayMaker for example,

 Bye,

 Jean
« Last Edit: April 27, 2015, 03:43:08 AM by jeanfabre »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Activate/Dectivate by Tag
« Reply #5 on: April 26, 2015, 07:27:02 PM »
I tried the ecosystem 'activatebytag' and at the top of the script got this link by graham.  I am not sure if this is the same thing.  I do see you 'deactivate by tag'.  You mention that the activate won't work, but in this script on the ecosystem is has a option for on or off.  This actions will deactivate but not activate.  Is this yours or was modified or does it work or what?



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: 15500
  • Official Playmaker Support
Re: Activate/Dectivate by Tag
« Reply #6 on: April 27, 2015, 03:44:09 AM »
Hi,

 yep, Graham action is only for deactivating, see my post on your other thread.

http://hutonggames.com/playmakerforum/index.php?topic=10213.msg48230;topicseen#msg48230

Bye,

 Jean