Modifiers

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.

Included Modifiers

The following table explains the modifiers which are currently included with FlexiMotion. Most of them are demonstrated in more detail by the Samples.

Name Sample Description
AccelerationModifier External Forces Adds velocity to the simulated objects in a specific direction. This can be useful for things like gravity.
DistanceBasedUpdateRateModifier Update Rate 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.
PreWarmModifier None Immediately updates the simulation several times on startup to allow it to stabilize before the player sees it.
ScaleModifier Scale 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.
SimulationRootModifier Simulation Root Changes the simulation to be in an object's local-space instead of the default world-space.
SphereCollidersModifier All Prevents the simulated objects from going inside spheres attached to other objects. See the Colliders page for more details.
WindModifier External Forces An AccelerationModifier which randomizes its acceleration every frame to act more like wind and can apply temporary gusts.

Custom Modifiers

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:

Interface Description
JobModifierGroup.IOnInitialize Runs when the simulation is initialized.
JobModifierGroup.IOnReEnable Runs when the simulation is enabled again after having previously been disabled (i.e. not the first time it's enabled after being created).
JobModifierGroup.IPreUpdate Runs at the start of an update.
JobModifierGroup.IOnUpdate 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.
JobModifierGroup.IPostUpdate 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 JobModifierGroup which can be accessed via FlexiMotion.Modifiers.
  • Those lists are SortedLists which use an int to 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 JobHandle parameter to use as the dependency for any jobs they schedule and return the JobHandle those newly scheduled jobs (or just return the given parameter directly if no new jobs are scheduled).