playMaker

Author Topic: Activate GameObject by Tag[SOLVED]  (Read 8046 times)

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Activate GameObject by Tag[SOLVED]
« on: January 06, 2013, 08:00:53 PM »
Hi all,

I'm using a simple Menu system and need to turn some interactive objects off when the menu is displayed. I searched for a way to disable based on tag - but could only find "Destroy by Tag":

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

Is there a simple way I can tag the objects I want to deactivate/activate when the menu is displayed?

Thanks!
JK
« Last Edit: January 08, 2013, 03:26:06 PM by jeanfabre »

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Activate GameObject by Tag
« Reply #1 on: January 06, 2013, 08:30:07 PM »
Don't know about deactivating them - are they UI elements or what? Is the menu a seperate scene for itself or? I need some more info to go on :)

My first idea is to just add an event that when the menu is opened, set those objects alpha to 0 - effeciently making them invisible

or destroy them and spawn them back by using prefabs
Remember, you don't fail unless you give up trying to succeed!

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Activate GameObject by Tag
« Reply #2 on: January 06, 2013, 08:42:56 PM »
@Koz

Thanks for the speedy response. The menu is a part of the same scene. The objects are GUI, but they have touch events on them, so I need them to be de-activated rather than invisible or destroyed (as I have to enable them back into the same spot).

De-activating them works, but at the moment I have to deactivate them all by name using Activate Object. As I'm using this menu across a few scenes, I'd like to be able to look for a Tag and turn the objects off based on the tag as opposed to individually turning off the objects per scene.

I hope that makes sense!

JK

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Activate GameObject by Tag
« Reply #3 on: January 07, 2013, 02:13:56 AM »
Hi,

 there is a "Set Tag" action: https://hutonggames.fogbugz.com/default.asp?W74

have you tried that? that should work.

the other possibility would be to use a hashtable ( key/value pairs) to store references of your menu items gameObjects against a reference key. then you simply query the hashtable for a given reference, which will return you the gameObject, and you can then do whatever. It will be slightly more involving to start with, but will give you a good result too, just as setting tags ( problem with tags, is that you can only have one per gameObject, where you can store multiple times the reference of a gameObject, which means you could access an item given different keywords).


bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Activate GameObject by Tag
« Reply #4 on: January 07, 2013, 06:08:16 AM »
Yeah I think a hashtable would be a good solution ^

If you think it's too complicated, then using the "activate gameobject" action to deactivate when menu is opened is really simple, and you can always right-click and copy FSM or copy State and just paste them on the other elements - shouldn't take too long :)
Remember, you don't fail unless you give up trying to succeed!

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Activate GameObject by Tag
« Reply #5 on: January 07, 2013, 04:28:43 PM »
@Jean Thanks for the comprehensive answer - but I think your solution is too complex for my skill level. I had a look at SET TAG, but this doesn't help unfortunately.

@Koz Thanks again for your help. I'm using Activate Object at the moment, but the problem is I'm using it across scenes, so every time I update the menu prefab, it loses the connection to those objects in every scene. This is why I need a solution that can work on a global level as opposed to a per scene basis. I thought tagging or layers would be a great way to turn objects on and off without having to name those objects directly...?

Thanks for the responses guys - but I'm still looking for a simple answer.

To clarify: I'm using a menu prefab. It's working fine, but when I update it in one scene - it loses all of its "Game Object Name" connections in every other scene.

So I need an action that will activate objects without me having to name them specifically, so the menu prefab works across all scenes even after I update it.

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Activate GameObject by Tag
« Reply #6 on: January 07, 2013, 04:44:39 PM »
I've found this which may help?

http://answers.unity3d.com/questions/52855/activating-game-objects-with-a-tag.html

ps. I'm an artist - so please forgive my level of ineptitude ;)

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Activate GameObject by Tag
« Reply #7 on: January 07, 2013, 10:05:54 PM »
Hi all,

Not sure if this is the most elegant solution... but I believe I've solved my issue.

  • I created an empty GameObject and placed the objects I wanted turned off/on within
  • I applied a Set Game Object (Global Variable) on that Object - which I edited to enable "User Owner"
  • Then in the menu I used Activate Game Object and reference the Global Variable to activate and deactivate

It's not very elegant, but it works across all scenes.

JK

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Activate GameObject by Tag
« Reply #8 on: January 08, 2013, 01:56:41 PM »
that sounds like a good solution, I'm glad you made it work :) Also thanks for sharing how you solved your problem - this will surely help someone in the future that searches for the problem and finds this topic :)

-Koztheboss
Remember, you don't fail unless you give up trying to succeed!

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: Activate GameObject by Tag[SOLVED]
« Reply #9 on: February 26, 2013, 08:58:16 PM »
Would this work for a in Game Menu, I set up the IGM(In Game Menu) to use Get Key, set it to Esc and set the Bool to true, then added get Activate Game Object set that to the IGM and the Other Textures inside it, but when I got to play it, it Disables the FSM right way and Pressing ESC doesn't work

attached a pic, of the fsm