Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by MarkenhXu · Jan 09, 2019 at 10:40 PM · databasedatasingleton

Where do I put gamewide constant variables

If I have 2 squad type. Regular and Elite.

A regular squad can have 9 units per squad, and an Elite squad can have 4. A squad spawner may refer to this data, different squad that is already spawned may refer to this data when getting reinforced etc etc.

I feel like the "max number of units" setting should be stored in a database or a static data class. so it only exist in 1 place.


  public enum SquadType
     {
         Regular,
         Elite,
     }
 
 [System.Serializable]
 public class SquadSettings
     {
         public SquadType squadType;
         public int MAX_NUM_OF_UNITS;
     }
 
 [SerializeField] List<SquadSettings> SquadSettings = new List<SquadSettings>();



Where do I put this SquadSettings list?

Maybe a Singleton GameManager script attached to an empty gameobject that persist through each scene?

Comment
Add comment
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

1 Reply

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

Answer by sean244 · Jan 09, 2019 at 10:51 PM

You should definitely put it inside of a singleton. What your describing sounds exactly like a manager class - which would be a singleton. So you can either put it in your GameManager, or something more specific, like a UnitManager. But yes, a singleton is definitely the way to go.

Comment
Add comment · Show 2 · 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 MarkenhXu · Jan 09, 2019 at 11:03 PM 0
Share

Also as a general follow up question. A complete game would have lots of settings like these. Do I just make a bunch of different singletons, like a Unit$$anonymous$$anager for all unit related settings, a $$anonymous$$usic$$anonymous$$anager for all music related settings? and put all those Singleton in the same empty game object. Is this how everyone does it? It feels logical.

avatar image sean244 MarkenhXu · Jan 09, 2019 at 11:10 PM 0
Share

Of course. This is very, very common. $$anonymous$$ost games have several different managers: A Game$$anonymous$$anager will handle general things like pausing, restarting, and quitting the game; a Level$$anonymous$$anager will handle things having to do with the actual level, like opening a gate after all the enemies are killed; a UI$$anonymous$$anager will handle things having to do with the user interface, like displaying the pause menu or main menu; of course an Audio$$anonymous$$anager is standard practice; and a Unit$$anonymous$$anager is also very common for mmorpgs and rts games. It's very standard to have multiple singletons in your game. It's practically the norm.

[EDIT]

I just re-read your question and you asked if all of these mangers should be attached to the same gameObject? No. They definitely should not be attached to the same gameObject. Each $$anonymous$$anager exists as it's own gameObject. So in the hierarchy, you should see one gameObject called 'Game$$anonymous$$anager', another one called 'Audio$$anonymous$$anager'...so on. If you want to see an example of this, you can clone my platformer game that I made in Unity https://github.com/sean244/Braid-Clone It uses several different manager classes like the ones I described above. I'm also working on a rts game of my own if you want to see a preview of that https://www.youtube.com/watch?v=9ELUwr9k42g

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

101 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 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 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

What is the best approach to filter large data sets in Unity? 1 Answer

Too large String Array which created from DB 0 Answers

How do you store non-GameObject data? 3 Answers

Database-like arrays 1 Answer

Data Management Issue - How to manage retrieved data from mysql? 0 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