Hide GUI elements without disabling GameObjects using Playmaker custom action

Nuclear Napalm Development 2 Comments

Working on my current project in Unity I encountered situation when I need to hide/unhide some GUI elements. The first easiest solution that comes to mind is just disabling/enabling GameObject using following piece of code:
gameobject.SetActive(false);
I quickly refused this solution and here are 2 main reasons:

  • You can’t interact with disabled gameobjects and their components from script
  • You can’t change states and send events to disabled gameobjects using PlayMaker FSMs

I started looking for some workaround…


 There IS solution

Canvas Group ComponentI found solution which allow to hide GUI elements without disabling GameObjects using Canvas Group component. This component allows you to change transparency of GUI element and all its child objects (e.g. text on Button) as well as “Interactable“, “Blocks Raycasts” and “Ignore Parent Group” parameters. It works really well. You can easily access and manipulate all these parameters from script. Unfortunately, I didn’t find any action to modify Canvas Group component either inside PlayMaker or Hutong Wiki nor in Eco and Google. So I decided to write my own action.


 “Set Canvas Group Properties” Playmaker action

Download Set Canvas Group Playmaker action 

To install this action:

  • Download RAR-archieve
  • Back-up your project
  • Extract cs-file to your Assets folder (you must have Playmaker imported to your project)
  • Wait until script compiled
  • PROFIT!

Then go to Playmaker Action Browser and type “Canvas” in search field. You should see something like this:

Canvas Group Action Search

And if you add this action to state it should look like this:

Canvas Group Action

Remember
to make it works you must attach CanvasGroup component to GameObject!

Conclusion

Now you can easily change transparency of any uGUI element, access hidden elements from script or FSM and do a lot of cool stuff! If you encountered any problems with this Playmaker action please let me know in comments.
If you’ve found this article useful, please share it with your friends using social buttons below.

Thanks for reading, stay tuned!

Nuclear NapalmHide GUI elements without disabling GameObjects using Playmaker custom action

Comments 2

Leave a Reply