Scheduler
Description
The Scheduler is an important component in FP Motion; its main function is to allow developers to run certain motions with delays, loops, or other 'playback' functionality.
Some components that use the Scheduler are:
Land Component. This component uses the Scheduler to apply a force for a couple of seconds once the player lands. This provides a much nicer effect that applying it all at once.
Non-Monobehaviour Updates. Some components use the Scheduler as a replacement for being a
MonoBehaviour
. The way this works is by subscribing to it, and the Scheduler invokes the subscribed function on an Update.Complex Motions. We will include more complex motions like reloading in the asset, the way we will make them work is by relying on the Scheduler’s capabilities.
How does it work?
The inner workings of this component are fairly simple, it receives requests for things that need scheduling, whether they be on an update function, or after a certain period, and fulfills those requests.
Scheduling
The way to schedule something to happen is by using the TickSchedule method, which looks the following way:
All this function does is take a method, and schedule it to get invoked inside an Update, FixedUpdate, or whatever the developer picks as a scheduledTime.
The duration determines the time that it will stay scheduled, when that timer ends, the method is removed from that scheduling and stops being invoked.
Usage
To use the Scheduler there is a need to first access it. We made this simple by making it a Singleton.
To access the instance of this component:
Now the TickSchedule function can schedule methods, a good example would be:
A good example of how scheduling can produce cool results is the Land component.
Last updated
Was this helpful?