Easily Manage the State of Your UI With This Pattern to Save Yourself Headaches | Unity Tutorial

preview_player
Показать описание
On your UI do you have references from random scripts to other scripts to manage which one should be showing? Are you setting up the state of the next page in code where your UI scripts are tightly coupled?

In this video I'll show you the pattern I've been using for the last 6 years to remove that mess and separate the concerns of UI Sounds and Animations into a "Page" Monobehaviour that is controlled by the MenuController. With these two simple, but powerful scripts you can easily manage your UI page state in a simple, predictable, and powerful way.

At the end of this video you'll have:
A structured, proven paradigm to approach to managing pages on your UI
An easy way to decouple your animation and sound playing from your UI logic.
A tool to intelligently control what needs to be set up, when it needs to be set up, instead of having that hard coded in your scripts.

🧡 Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:
📚 Take my Unity ShaderGraph Course:

Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.

Chapters
00:00 Introduction - What to Expect
03:24 Scene Overview
14:10 Hooking it all up
16:50 PlayerInput - Escape to go back
17:46 Demo
19:21 Explanation of Event Order
20:21 Setting up Events in the Editor
20:57 Demo - Events and Exit On Page Push
21:33 Closing
Рекомендации по теме
Комментарии
Автор

It’s recommended that you have multiple canvases with a single UI object rather than having a single canvas with multiple UI as child objects. This is because each time a canvas is active, it is going through every single child object checking to see if it needs to be rendered on screen, if it is active and enabled, etc.

lolgube
Автор

Hi, I haven't finished the video yet but I will as I found your way of making the UI interesting from the Intro alone, I just wanted to share a piece of advice, many people for some reason use Awake to grab components but an even better alternative would be to grab them in Editor just to save a bunch of operations during gameplay. Monobehaviour provides a method called Reset() which is called when a component is added or reset. With that you can grab everything you need even before a build.

TheGravityChannel
Автор

I just strugled with the UI in the past few months and finally I figured it on myshelf how it worth to do.. Definetelly the way as you suggest it also. So I dont know how much people undeerstood it (from the like giving peoples) but this video is more important as it seems at the first time. Thank you for it. I will consider your suggestions and improve my game with them.

Ferenc-Racz
Автор

Thank you for this video, it is the most informative video about Unity UI so far. I loved the Page concept, it helped me to organize and simplify my project UI. I did some changes, instead of keeping all the secondary pages visible and around the main, I'm keeping them inactive and activating/deactivating on the Enter/Exit events. Another change was moving the audio source out from the pages. Again, thank you for this video.

rodgarcialima
Автор

This is essentially just the state pattern being used for menus. I often do the same thing myself.

dopplegangerdavid
Автор

Great video as always! This seems to be the same system you have in Llama Survival and I'm curious about what happens after you press play? Are you loading a new scene when that happens or is all of this under one scene and you are just hiding the menu after the game is ready to start playing?

sumnererhard
Автор

I have a feeling this doesn't support controllers properly as the input focus isn't passed from active panel. So input made in one panel will also be caught in another panel. Am I right?

maximdaigle
Автор

Your background is different. Are you traveling for the holidays?

poobagification
Автор

hi, i would like to know where can i download or get the player input, I was stuck in that part . thanks!

simonyeung
Автор

Great video 😎👍 where do you find motivation to do videos? 🙂 I cant start my own series on YouTube already 2 years. Probably I am not afraid, but every time I find some excuses and other tasks to do.. 😔🤷🏻‍♂️

Raccoon
Автор

I used another script at my last page start button to load another scene and when i load back the menu scene again its gone

hassanshah
Автор

could you make a c ++ basics tutorial that explains what different things are

MDT
Автор

You made a 22 minute video about stuff I do not care about. I thought this was about managing the state of the UI. If I wanted to watch a video about fading in, fading out, sliding in, sliding out, audio this, audio that, i would have searched for a video about that. I thought this was about managing the state of the UI. This could have been a five minute video.

Vyrulian