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 /
This question was closed Mar 30, 2014 at 10:59 PM by getyour411 for the following reason:

Too subjective and argumentative

avatar image
0
Question by jkh13 · Mar 30, 2014 at 10:26 PM · designstatestate-machine

Implementing a game state system

I am implementing a turn based strategy game and was thinking about what the convention in Unity is to handle state transitions and logic. If I were to code it myself I would implement it using a stack whereas each object in the state implemented an interface "GameState" and each of these states has its own update logic and state info. The top most state is the "active" state and can transition be either adding a new state on the top of the stack or to pop itself off the top (returning "active" to the state below it).

Initially I thought of implementing a single monoBehaviour for each state and have a "master" monoBehaviour hold the stack. I would add the monobehaviours to the gameObject when I add them to the stack and remove them when popping. I would make sure setActive(false) is set for all monobehaviours not on top of the stack. However this doesn't seem to work as you cannot pass an instance of a component to addComponent() and the gameStates require construction parameters.

My next thoughts were to not implement monobehaviour on the states and rely on the "master" monobehaviour to call update manually on the top state. This seems to go against the Unity Model though as I would be re implementing parts of the standard monobehaviour interface (update, awake, destroy e.t.c.).

What would be the optimal way to acheive such a state system?

Comment
Add comment · Show 1
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 getyour411 · Mar 30, 2014 at 10:59 PM 0
Share

" If I were to code it myself I would..."

The optimal way is the one which you can code and maintain for your platform and performance requirements. Open-ended discussions like this are better suited for the Forums as your reponses here are likely to be subjective.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Switch animation state while keeping animation timing 0 Answers

Checking Transitions in Animator 0 Answers

Can an empty state in Animator cause performance issues? 1 Answer

moving gameobject from state machine behaviour/different code result from inside OnStateExit() 1 Answer

Calling a function outside the Finite State Machine 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