Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
0
Question by mossbeard1 · Jan 15, 2021 at 06:40 AM · performance optimizationscore systemmanagerarchitecturescoreboard

gamemanager: monobehaviour, scriptable objects, or static class

hey all,

im currently in the process of creating a new game and am going to be creating a manager that holds a score that refreshes every level.

moving forward i see 3 ways of doing this. 1. a simple component that inherits from monobehaviour and lives in the scene on an empty gameobject 2. a scriptableobject 3. a static class

im wondering what is the standard approach?

personally i think scriptableobject or static class is the best approach but curious on opinons

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
1
Best Answer

Answer by jackmw94 · Jan 15, 2021 at 09:40 AM

I would advise going with a singleton monobehaviour. You can implement this easily by having a static instance of your monobehaviour that allows static access to it like so:

 public class GameManager : MonoBehaviour
 {
     public static GameManager Instance;
     
     private void Awake()
     {
         if (Instance)
         {
             throw new Exception("GameManager already present in scene!");
         }
         Instance = this;
     }
 }


I've also seen packages that can make the whole singleton pattern a little more cleanly: https://github.com/kleber-swf/Unity-Singleton-MonoBehaviour

Having it as a monobehaviour allows you to see and edit its properties in the inspector which is a lot nicer than having to hard code config changes to a static class. Since it's following a singleton pattern then it's just as accessible as a static class.

A scriptable object would be a good way to store a set configuration for a game manager but less suitable for the whole game manager class - think of scriptable object as data storage with a nice inspector interface. Since a game manager will have lots of runtime data that it's managing and references to scene objects, it makes sense that it too should be an object that lives in scene and that it shouldn't be trying to persist objects that only exist in scene :)

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 mossbeard1 · Jan 15, 2021 at 04:01 PM 0
Share

thank you so much! Learning the balance between unity scripting and traditional c# has been an educational challenge so i appreciate your deep dive :)

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

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

Scoring System 3 Answers

controller/manager architecure 2 Answers

how to creat and scoring and high score system for an endless runner,how do I display my score on a game over scene and also create and high score system for the same ? 0 Answers

How to make a scoreboard? 0 Answers

Help With Score Controller - Can You Only Have One? 1 Answer


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