Modifiers are components which allow you to change the behaviour of the simulation. The most common is the
SphereCollidersModifier explained on the Colliders page and the others can all be found in the
FlexiMotion -> Modifiers menu.
It's usually best to add modifiers to the same object as the
FlexiMotion component they will modify, but you can put them anywhere you want. For example, you could write a script to add a
WindModifier to any character who enters a windy area rather than having that modifier as part of every character's prefab all the time.
The following table explains the modifiers which are currently included with FlexiMotion. Most of them are demonstrated in more detail by the Samples.
|Adds velocity to the simulated objects in a specific direction. This can be useful for things like gravity.
|Changes the number of
Updates Per Second based on the distance from the simulation to the camera (or another target object) to save performance by spending less time simulating objects that are less visible on screen. Also disables the simulation entirely if it gets too far away.
|Immediately updates the simulation several times on startup to allow it to stabilize before the player sees it.
|Accounts for scaled objects. Without this modifier, Colliders will assume that the scale of every object is
(1, 1, 1) so if that's not the case you should add this modifier.
|Changes the simulation to be in an object's local-space instead of the default world-space.
|Prevents the simulated objects from going inside spheres attached to other objects. See the Colliders page for more details.
AccelerationModifier which randomizes its acceleration every frame to act more like wind and can apply temporary gusts.
This section explains how modifiers work in case you want to implement your own.
All of the included modifiers inherit from
FlexiMotionModifier which simplifies the initialization and cleanup, but that isn't strictly necessary. The actual modifying functionality is implemented via the interfaces in
JobModifierGroup which each contain a single function:
|Runs when the simulation is initialized.
|Runs when the simulation is enabled again after having previously been disabled (i.e. not the first time it's enabled after being created).
|Runs at the start of an update.
|Runs after each iteration of an update. If multiple updates occur in a row due to the
Updates Per Second, this will run for each one.
|Runs after all iterations of an update. If multiple updates occur in a row due to the
Updates Per Second, this will only run once after all iterations.
- Each interface has a corresponding list in
JobModifierGroupwhich can be accessed via
- Those lists are
SortedLists which use an
intto determine their execution order.
- Lower numbers execute first.
- Every modifier must have a unique execution order value.
- If a modifier implements more than one of the interfaces, it can use a different execution order value for each list.
- The interface functions all receive a
JobHandleparameter to use as the dependency for any jobs they schedule and return the
JobHandlethose newly scheduled jobs (or just return the given parameter directly if no new jobs are scheduled).