Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by SimpleGiant · Jan 10, 2016 at 06:01 AM · codepagemetaprocessflow

Creating A Proper Game Manager

I am trying to learn how to use a game manager properly or some other solution. From what I understand, I store things in it that are not just variable to the one scene, or may want to be recapped latter.

For example I cant find any answer on how to rig Unity.UI to the game manager properly. I end up with more than one instance of a game manager due to scenes loading.

How do I work around this? This seems to not be a common topic of discussion. What is the proper way to do this, because I understand that their are many ways to get the job done. What way is the best?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image corn · Jan 10, 2016 at 11:16 AM 0
Share

Could you provide more details ? Like the contents of your Game$$anonymous$$anager script, the structure of your prefab, the calls on your buttons' onClick events... all things that are relevant.

Also, why do you need a different Game$$anonymous$$anager for each scene ? I don't see the purpose of using DontDestroyOnLoad on your Game$$anonymous$$anager only to have it destroyed by another object right after the loading of the second scene. Wouldn't it be more convenient to use a single Game$$anonymous$$anager ?

avatar image Fattie · Jan 10, 2016 at 03:25 PM 0
Share

Yes, like Corn I am mystified by the comments about the buttons. Just mark the buttons DDOL

You must have a "pre-launch" scene (100% of projects have to do this), just put them in there as DDOL

This is ubiquitous in Unity. Indeed it often leads to discussions such as ... http://answers.unity3d.com/questions/441246/editor-script-to-make-play-always-jump-to-a-start.html

3 Replies

· Add your reply
  • Sort: 
avatar image
15
Best Answer

Answer by Fattie · Jan 10, 2016 at 03:20 PM

This entire issue is

INCREDIBLY OUT-OF-DATE

There's just nothing to it these days ...

CLICK HERE for an explanation -

http://stackoverflow.com/a/35891919/294884

it is dead simple. There's just nothing to it.

If you do want to use the Grid.cs script - note that the only benefit is you save typing ONE line of code - just go here for the latest version ...

http://answers.unity3d.com/answers/663681/view.html

Cheers.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChristopherWood · Jun 10, 2016 at 11:46 PM 1
Share

How is this not upvoted a hundred times already? It should be required reading. I've only been learning Unity for two months, and a third of that time was wasted trying/failing to make singletons work. Now the scales fall from my eyes and my scenes transition like butter. Thank you, Fattie, for the Grid! So simple ... brilliant brilliant brilliant.

avatar image Fattie ChristopherWood · Aug 10, 2016 at 03:34 AM 0
Share

Hi @ChristopherWood - right, there can no more be "singletons" or even "classes" in Unity than you could have OO and Classes in say Photoshop or $$anonymous$$icrosoftWord.

It's just that there is a huge amount of incredibly out of date trash on the issue on the web, so there is a lot of confusion

It is just this simple ...

http://stackoverflow.com/a/35891919/294884

avatar image orchard800 · Jul 18, 2016 at 04:04 AM 0
Share

Thankyou!!! I've been learning Unity and c# for the last couple of years and I've really struggled with how to implement a proper game manager. I've finally got my combat/floating text manager working!! :D

Question: Why does every project need a preload scene??

I now have a preload scene before my main menu scene - but I'd like to know, what does this do that my main menu scene wasn't already doing? Surely it's just placing the __holder object?

avatar image Fattie orchard800 · Aug 10, 2016 at 03:35 AM 0
Share

Correct, the raison d'etre of a preload scene is simply to hold all of your "You need them everywhere" components (like sound effects, scoring etc). You're 1000% correct.

Unity famously do some staggering silly things. The fact that they forgot to inherently include a preload scene in Unity is just beyond human belief. It's very likely they will do it in Unity7 and the issue will never come up again.

It's the most absolutely silly thing in all of Unity.

avatar image MerlinsMaster · Jan 21, 2020 at 06:22 AM 0
Share

In your post on this subject at Stackoverflow, you said, "Note that you can not use "splash screen" or "menu" as the preload scene." Out of curiosity, why? For a while, I was using a completely empty preload scene to deploy my "general behaviors", but after a time, it just seemed unnecessary, so I started using my Splash scene as a preload scene. If there is some significant downside to this, could you explain to me what that is?

avatar image Max_Bol MerlinsMaster · Nov 09, 2020 at 05:17 AM 0
Share

The only real reason to not use the splash screen would be a case where the amount of data handled in the "general-needed behaviors" is so great that it has a immediate impact on the splash screen content. Having the game hanging even just 1 sec during the beginning of the splash screen isn't really a good start. By having a separated preload scene, you ensure that the game only "hang" during the App/Software opening, before the splash screen even starts.

avatar image
8

Answer by Fritsl · Nov 02, 2017 at 10:08 AM

@Fattie: Thanks for elaborating all this, it's great!

There is a point though that people are trying to get through to you, and I'll just give it a go as well, and since this is spread across to StackOverflow, forgive me a double post, but I think this is rather important to know for newbees specially since this post is high in Google ranking:

Having a "Preload" is a very good tip etc. But you take a step further, and there's an issue there.

We do not want every instantiation of everything in our mobile games to do a "FindObjectOfType" for each and every every "global class"!

Instead you can just have it use an Instantiation of a static / a Singleton right away, without looking for it!

And it's as simple as this: Write this in what class you want to access from anywhere, where XXXXX is the name of the class, for example "Sound"

 public static XXXXX Instance { get; private set; }
 void Awake()
 {
 if (Instance == null) { Instance = this; } else { Debug.Log("Warning: multiple " + this + " in scene!"); }
 }

Now instead of your example

 Sound sound = Object.FindObjectOfType<Sound>();

Just simply use it, without looking, and no extra variables, simply like this, right off from anywhere:

 Sound.Instance.someWickedFunction();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image monark · May 13, 2020 at 09:31 AM 0
Share

You could make the logging stronger using DebugError("Error: multiple instances detected", this); Debug will take the current GameObject as a second parameter

avatar image
1

Answer by Notter · Jan 10, 2016 at 04:00 PM

You don't need a prefab of the GameManager. Just put the script on an object in your first scene.

make the script a singleton, and make sure to add "DontDestroy(gameObject); this will make it so the object will stay alive between scenes, which means you don't need to place it in every scene.

that being said.. if you want to test other scene without loading the first scene, then you'll need to place the gameManager in each scene (but remember to remove/disable it later)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Jan 10, 2016 at 04:40 PM 0
Share

There are no singletons in Unity, Unity is an ECS system.

avatar image Notter Fattie · Jan 10, 2016 at 04:47 PM 0
Share

What you're describing is just a singleton that has all your other singletons inside it.

And i don't understand why a singleton can't be a $$anonymous$$onoBehavior. in the Rogue-like tutorial they show an example of a Game$$anonymous$$anager and Audio$$anonymous$$anager which are Singletons.

avatar image Fattie Notter · Jan 10, 2016 at 05:05 PM 0
Share

No, it's not a singleton dude. Singletons don't really work in the c#-Unity environment.

It's actually just a static class that you use "trickily" in a way that looks and performs exactly like a real singleton.

It's kind of syntactic sugar you know? Easy!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

44 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Understanding UI Logic 0 Answers

Make game run faster . how ?? 2 Answers

I want to export from Unity to Oculus Rift. I'm using Unity 5.1.2p3. 0 Answers

Debug Statement Doesn't Work? 2 Answers

Why is the user SisterKy breaking UnityAnswers? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges