Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 StewedHarry · Nov 07, 2020 at 12:57 PM · systemlogicarchitecture

Game organisation - persistent game logic and state

I’m starting to build a prototype of a game and I’m wondering how to structure the project. So far my unity projects have been single scene tests, so I’m now thinking about how I would go about expanding and scaling a game spanning multi scenes and systems.

My main question concerns how to share game logic among various scene given Unity’s script-component system. I understand in other game engines it is possible to have a ‘main’ entry point for scripts which can serve as a means to call procedures which control game logic which persist throughout the gameplay loop – e.g. managing player input, changing scenes, etc.

There are probably a range of ways to implement this within Unity, but are there any best practices? I was thinking of implementing a main prefab which is present in every scene. This would contain a hierarchy of GameObject and components which would manage the game logic.

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

Answer by CodesCove · Nov 07, 2020 at 06:43 PM

Some suggestions...

Keep your initial and run time persistent data (over scene changes) in Scriptable objects. You can refer from there the the actual GameObjects (not in serialized way) or Prefabs (and vice versa trough hook component you need to make). This way you can also destroy GameObject (like store it to inventory) and instantiate it with runtime values stored in Scriptable object (like taking it out of inventory or in scene change). You can also extend from here to build save load system quite easily. There is some coding to be done for sure but this way its pretty generic. https://docs.unity3d.com/Manual/class-ScriptableObject.html, https://unity.com/how-to/architect-game-code-scriptable-objects.

Also try to steer way from centralized controls like GameManager etc (that usually use singleton patterns and Object.DontDestroyOnLoad) and try use patterns that don't create strong dependencies. Check how to use delegates to create service subscription / event based services. If you need some centralized control then, instead of GameManager, build EventManager as a place to subscribe event listeners and fire events (this don't need to be Monobehavior derived, but independent static class or SO)

Referring to your example about managing player input. You can have that GO and component created in every scene separately (it can have common prefab and have instance in every scene).. If it's controlling some objects in the scene you can refer to those via scriptable object or fire events that the interested objects are listening..

All in all there's tons of material, tutorials, opinions about theses patterns in the net and I know only few of these patterns.. so above is just my 5 cents.. Hope you get things started (and also finished)!

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

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

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

Accessing local system ( File Browser ) 2 Answers

How can I change the button's color back to its previous state? 0 Answers

Randomly place a specific number of objects? 1 Answer

int.Parse(), float.Parse(), double.Parse() all not working when exported,int.Parse, float.Parse double.Parse all not working 1 Answer

New Input System: Detect if input is used by UI 3 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