Unity logo
Cancel
Cart
Applications
Sell Assets

Over 11,000 five-star assets

Rated by 85,000+ customers

Supported by 100,000+ forum members

Every asset moderated by Unity

Home
Tools
Utilities
1/10
SubRoutines run background tasks based on specific conditions, can be paused and chained for flexibility, and serve as customizable event system in games and other applications.
Render pipeline compatibility
The Built-in Render Pipeline is Unity’s default render pipeline. It is a general-purpose render pipeline that has limited options for customization. The Universal Render Pipeline (URP) is a Scriptable Render Pipeline that is quick and easy to customize, and lets you create optimized graphics across a wide range of platforms. The High Definition Render Pipeline (HDRP) is a Scriptable Render Pipeline that lets you create cutting-edge, high-fidelity graphics on high-end platforms.
Unity VersionBuilt-inURPHDRP
2020.3.43f1
Compatible
Compatible
Compatible
2019.4.39f1
Compatible
Compatible
Compatible
Description

SubRoutines

--------------------------------------------------

What are SubRoutines and why would I need them?

To put it simply once created, a sub routine will run in the background performing an action until a condition is met. Fleshing this idea out further we can build many complex tasks that can run concurrently or within a chain of events, while adding features that makes awkward development much easier to write and code that is easier to read at a glance.

Another handy feature is the ability to pause a routine at any time, and chain routines together. This allows for great flexibilty and can act (or be further extended to act) as a very customisable event system for your game. You have full control of how a routine is run.


How does it work?

Many varieties of tasks can be defined by 2 simple things: a condition and an action. This package provides all of the background work by testing and running these tasks according to the current frame rate while giving a simple interface to create them. The package comes with a static class named SubRoutines which contains a variety of common understandable methods to easily interface with such as “Wait”, “While” and “RunFor”, which act as a great foundation for any type of time / condition based task.


See the documentation for more information on how to use the SubRoutines package and what it can be used for.


Public static methods (Called with SubRoutines.MethodName)

--------------------------------------------------

  • While: The foundational sub routine, use this to create further static routine methods. If condition is true then invoke action, otherwise invoke callback, then the sub routine will be automatically disposed of.
  • Always: Creates a sub routine that invokes action every frame.
  • When: Waits until condition is true and then invokes action.
  • Wait: Waits for the specified time and then invokes action.
  • RunFor: Invokes action every frame until the specified time is met, then finally invokes callback.
  • Repeat: Repeats action a certain number of times (or infinitely) every interval seconds.
  • RunNextFrame: Waits one frame and then calls action.
  • RunAfterXFrames: Waits numFrames frames and then calls action.
  • RunForXFrames: Invoke action for a specified number of frames (numFrames), passing the current number of frames elapsed into action (f), then invokes callback on the last frame.
  • Do: Call action immediately. Note that this is only ever useful within a chain of events.
  • Chain: Invoke a chain of SubRoutines, waiting for one to finish before moving on to the next. Note that Chains can be nested, which will be run concurrently by default.
  • GetInstance: Get game object instance.
  • RemoveSubRoutine: Remove a SubRoutine.
  • RemoveAllSubRoutines: Remove all SubRoutines.

Documentation:

-----------------------

https://mugheadstudios.com/files/SubRoutines_Documentation.pdf?2


Contact:

-----------------------

Any questions or suggestions? Please feel free to contact me at zephni@hotmail.co.uk


Sub Routines

(4)
10 users have favourite this asset
(10)
$4.99
Seat
1
Updated price and taxes/VAT calculated at checkout
Refund policy
This asset is covered by the Unity Asset Store Refund Policy. Please see section 2.9.3 of the EULA for details.
Secure checkout:
Supported payment methods: Visa, Mastercard, Maestro, Paypal, Amex
License type
File size
300.7 KB
Latest version
1.02
Latest release date
Jan 5, 2023
Original Unity version
2019.4.39
Quality assets
Over 11,000 five-star assets
Trusted
Rated by 85,000+ customers
Community support
Supported by 100,000+ forum members
Unity logo
Language
Feedback
Partners Program
Partners
USD
EUR
Copyright © 2025 Unity Technologies
All prices are exclusive of tax
USD
EUR