playMaker

Author Topic: Destroy Objects by tag  (Read 9290 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Destroy Objects by tag
« on: October 10, 2012, 03:55:52 AM »
Hi,

 Following a request,

http://hutonggames.com/playmakerforum/index.php?topic=2411.0

 Please find an action that will destroy all objects of a given tag. it has some options to delay or accumalate delay ( essentially being destroyed one after the other)


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Destroys all Game Object with a given tag.")]
public class DestroyObjectsByTag : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Tag)]
public FsmString tag;

[HasFloatSlider(0, 5)]
[Tooltip("Optional delay before destroying the Game Object.")]
public FsmFloat delay;

[Tooltip("if delay not 0, accumulate the dealy for object to be destroy, destroy them one after the other basically")]
public FsmBool AccumulateDelay;

[Tooltip("Detach children before destroying the Game Object.")]
public FsmBool detachChildren;

public override void Reset()
{
tag = null;
delay = 0;
AccumulateDelay = false;
detachChildren = false;

}

private float _delay;

public override void OnEnter()
{

GameObject[] gos = GameObject.FindGameObjectsWithTag(tag.Value);

       foreach (GameObject go in gos) {
if (detachChildren.Value)
go.transform.DetachChildren();

if (delay.Value <= 0 )
{
Object.Destroy(go);

}else{
if (AccumulateDelay.Value)
{
_delay += delay.Value;
}else{
_delay = delay.Value;
}
Object.Destroy(go, _delay);
}

       }

Finish();

}

}
}


bye,

 Jean
« Last Edit: October 10, 2012, 03:57:58 AM by jeanfabre »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Destroy Objects by tag
« Reply #1 on: May 23, 2014, 04:35:09 PM »
Love it.  Just download as asset and it is automatically added to list in playmaker.  Cool.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroy Objects by tag
« Reply #2 on: May 27, 2014, 07:18:14 AM »
Hi,

 Well, now there is even better, the ecosystem browser:

https://hutonggames.fogbugz.com/default.asp?W1181

get this, and then within Unity, you can search for let say "destroy", it will list that action, click on get for that action, and it will download it automatically and install it in your project for you.

Bye,

 Jean

Phuzz

  • Full Member
  • ***
  • Posts: 101
    • Bzilla Games
Re: Destroy Objects by tag
« Reply #3 on: May 28, 2014, 02:37:33 AM »
Hello,

I needed this action and it works exactly as expected, but one problem is when I build APK it doesnt seem to work on Android, is there a way around this or am I missing something? thank you
Bzilla Games "Education with a Tickle!"
Qbucket Games "Voxel Games"

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroy Objects by tag
« Reply #4 on: May 28, 2014, 03:55:28 AM »
Hi,

 I suspect your problem is earlier, I don't see why this action would perform differently. Could it be that your objects are not tagged properly on android for some reason?

 I would look into this first. Typically, I would make a scene with just one cube, tagged "hello" nad when you click on that cube you would call this action that destroy objects tagges "hello". If that works, then the action is working, else something is very wrong indeed, and I'll look further.


Bye,

 Jean

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 309
    • Andrii Vintsevych
Re: Destroy Objects by tag
« Reply #5 on: November 01, 2016, 11:46:41 AM »
@jeanfabre, it doesn't destroy disabled objects. Is it possible to fix this?

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: Destroy Objects by tag
« Reply #6 on: November 02, 2016, 09:51:08 PM »
Sadly GameObject.FindGameObjectsWithTag only has one parameter, tag.

https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html

I solution might be to add them to an array after disabling them.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroy Objects by tag
« Reply #7 on: November 03, 2016, 05:33:50 AM »
Hi,

 If you get ArrayMaker, you'll have an action ArrayListFindGameObjectsByTag which will give you all objects by tag in a list.



 Bye,

 Jean