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 SideKick · Feb 11, 2015 at 07:24 AM · c#pausingfinite-state-machine

Pausing a State Machine FlexFSM

Hi again,

I have been researching ways to create an FSM for resource collection, as my knowledge of C# is limited I'm searching for a goldilocks version (not too hard to understand at my current level of knowledge but efficient enough for it not to become a tangled mess.

I have come across FlexFSM which looks simple enough for me to get stuck into and edit however I'm having some problems figuring out how to add a pause when entering or exiting states.

Please don't laugh :)

I tried adding the following to the bottom of the Miner.cs;

         public void StartPause() {
             StartCoroutine(TestPause());
         }
         public IEnumerator TestPause(){
             yield return new WaitForSeconds(3f);
         }



And adjusted in MinerStates.cs;

         public override void OnEnter(GameObject owner)
         {
             miner.LogAction("Entering mine");
             miner.StartPause();
         }


To try and force a 3 second pause, this obviously did not work :) when loops become nested I have difficulty following actions through them. maybe that will just come with time.

I'm guessing I would need to adjust the following in Miner.cs to allow for pauses but, need some guidance if you have the time.

     void Update()
     {
         if (fsm != null && fsm.IsActive())
         {
             fsm.UpdateFSM();
             currentState = fsm.GetCurrentStateName();
         }
     }


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 SideKick · Feb 11, 2015 at 08:56 AM 0
Share

I have sort of got something working :)

changed $$anonymous$$iner.cs

     public bool alive;
     public float pauseTime = 0.0f;
     
     void Start()
     {
         Initialize$$anonymous$$inerData();
         $$anonymous$$akeFS$$anonymous$$();
         alive = true;
     }
 
 
     void Update()
     {
         if(!alive) {
             StartCoroutine(Pausing ());
         }
         while(alive){
             if (fsm != null && fsm.IsActive())
             {
                 fsm.UpdateFS$$anonymous$$();
                 currentState = fsm.GetCurrentStateName();
             }
         }
     }
 
     public IEnumerator Pausing() {
         yield return new WaitForSeconds(pauseTime);
         alive = true;
         pauseTime = 0.0f;
     }

and added to all enter/exit states on $$anonymous$$inerStates.cs

     public override void OnEnter(GameObject owner)
     {
         $$anonymous$$er.alive = false;
         $$anonymous$$er.pauseTime = 3.0f;
         $$anonymous$$er.LogAction("Entering $$anonymous$$e");
     }

but, it's not quite right, seems to only pause every now and again.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Baste · Feb 11, 2015 at 08:23 AM

The Waitforseconds does not halt the rest of the script, it just halts that one coroutine.

The easiest way to prevent your miner from moving for 3 seconds after it's created (if that's your goal), is to do this:

 bool canStart = false;

 void Start() {
     StartCoroutine(ActivateAfter(3f));
 }

 IEnumerator ActivateAfter(float seconds) {
     yield return new WaitForSeconds(seconds);
     canStart = true;
 }

 void Update() {
     if(!canStart)
         return;

     //Normal update stuff
 }


Sending the float argument in as an argument to the coroutine isn't strictly necessary, but I think it looks nicer like that.

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 SideKick · Feb 11, 2015 at 08:28 AM 0
Share

thanks for that I'll give it a shot, what I'm really after is a way to pause the OnEnter, OnExit, Reason, Act functions within a state in $$anonymous$$inerStates.cs which I think would help me debug problems later on

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

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

Creating a Branching Combo System using a FSM 1 Answer

Prevent Unloading assets for Reloading scene for a second time! 1 Answer

Lists as Parameters? 1 Answer

Problem with referencing gameobjects in a if statement 1 Answer

what is wrong with my script? (C#) 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