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 siddharth3322 · Apr 18, 2019 at 02:23 PM · script.coroutinetimecoroutinestime.deltatime

Time Manager Class Implementation Like Coroutine in Unity

I required to use multiple coroutines as per my game requirements but I found that its performance hungry. So I decided to write something own using Update method that behave similar to Coroutine in Unity. I can say its TimeManager class for implementation.



Main requirement, at a time I can run multiple instances of this TimeManager class because at many placed within the environment time based activities are running.

In this please give me, just an idea about kind of implementation remains good for me. I will do the code and share for other developers to use.

Comment
Add comment · Show 10
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 Bonfire-Boy · Apr 18, 2019 at 02:37 PM 0
Share

Tell us more. What exactly do you want this system to do? If it is in some way trying to achieve something that Coroutines could, but more efficiently, what makes you think you can do that?

And how many coroutines are you talking about? Personally I suspect that your issues are more likely to be do with how much you're trying to do (each frame) in those coroutines, than with how many of them there are.

In short, probably not worth bothering with this.

avatar image siddharth3322 Bonfire-Boy · Apr 18, 2019 at 02:44 PM 0
Share

Yes, I want to create something like coroutine - that wait for specific amount of time and after that call specific event. At a time, may be I am running with 8 to 15 coroutines currently and few of them are for longer waiting between 20 to 40 seconds.

Within performance improvement video published by Unity mentioned about this. It will always remain better if you use Update method rather than Coroutine within your game whenever you are looking for performance improvement.

avatar image Bonfire-Boy siddharth3322 · Apr 18, 2019 at 02:58 PM 1
Share

Ok. You have 8-15 coroutines that are just waiting? I don't believe that's the cause of your performance issues. What you're proposing sounds like a waste of time to me. But it'd be very simple to implement.... using Coroutines (basically you'd just step through them explicitly in your Update function rather than starting them with StartCoroutine)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cdr9042 · Apr 19, 2019 at 05:00 AM

You can do that, or add a custom timer script component to each object that you want to run a timer, then add a callback to the function you want to call after the timer run out

If you want to use TimeManager, you can try this

     public class FunctionCountdown
     {
         public float timeLeft;
         public Action functionCall;
 
         public FunctionCountdown(Action functionCall, float timeLeft)
         {
             this.timeLeft = timeLeft;
             this.functionCall = functionCall;
         }
 
         public void OnUpdate()
         {
             timeLeft -= Time.deltaTime;
             if (timeLeft <= 0f)
             {
                 functionCall();
             }
         }
     }
     
     //class TimeManager:
     List<FunctionCountdown> functionList;
 
     public void AddFunction(Action func, float time) //call this to add function and time to the list
     {
         functionList.Add(new FunctionCountdown(func, time));
     }
 
     private void Update()
     {
         foreach (var item in functionList)
         {
             item.OnUpdate();
         }
     }


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 Bonfire-Boy · Apr 19, 2019 at 09:43 AM 0
Share

How does this improve upon what you can already do with the Invoke function?

avatar image Bonfire-Boy · Apr 19, 2019 at 09:45 AM 1
Share

Oh, and you'll probably want to be removing entries from your list at some point :)

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

124 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

Related Questions

Can anyone tell how can i add 2 seconds to my TIMER from another script ? 2 Answers

Using Time efficiently regardless of current frame rate. 0 Answers

RPG Action Progress Bar always same speed 1 Answer

Returning an IEnumerator as an int? 1 Answer

Flashlight Cooldown and Timer 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