Enabling/Disabling SALSA Suite Modules

While SALSA Suite is very lean on processor cycles, there may be times where it is desirable to disable (and re-enable) modules based on some code-based criteria.

NOTE: If you are disabling modules, please do not disable the QueueProcessor. Doing so will likely cause some ambiguity in your model's animations. When enabled, it uses near zero processor cycles and simply checks to see if anything is in the queue -- if not, it returns. The only cycles used would be Unity calling the LateUpdate callback and the check for queue length. However, it will be necessary to ensure the queue is empty in some situations (i.e. disabling/destroying components that are being animated by the QueueProcessor).

SALSA LipSync

SALSA processing is very similar to the QueueProcessor, if the AudioSource is not playing, it will return. However, if you do need to disable the component, it is very straightforward. Enable/Disable it as you would any other component. It performs its disable housekeeping within the OnDisable callback. Likewise, it performs its enable housekeeping within the OnEnable callback. See example below.

EmoteR

EmoteR is slightly different with respect to what is running continuously. While it also uses very few processor cycles, if random emotes are enabled, it will be processing the random emotes over time. Just like SALSA, it is enabled/disabled just like any other Unity component. It performs its disable housekeeping within the OnDisable callback. Likewise, it performs its enable housekeeping within the OnEnable callback. See example below.

Eyes

The Eyes component is a bit different, namely because it contains 4 modules that can be independently switched on or off. Note the difference in enable/disable operations for Eyes in the example below.


Example code

using CrazyMinnow.SALSA;
using UnityEngine;

namespace DemoCode
{
    // Enable/disable SALSA & EmoteR just as you would any other Unity component.
    // Note the difference in enabling/disabling the Eyes component.
    public class DisableEnableModules : MonoBehaviour
    {
        public Salsa salsa;
        public Emoter emoter;
        public Eyes eyes;

        public void DisableModules()
        {
            salsa.enabled = false;
            emoter.enabled = false;

            eyes.EnableHead(false);
            eyes.EnableEye(false);
            eyes.EnableEyelidBlink(false);
            eyes.EnableEyelidTrack(false);
            // or...
            eyes.EnableAll(false);
        }

        public void EnableModules()
        {
            salsa.enabled = true;
            emoter.enabled = true;

            eyes.EnableHead(true);
            eyes.EnableEye(true);
            eyes.EnableEyelidBlink(true);
            eyes.EnableEyelidTrack(true);
            // or...
            eyes.EnableAll(true);
        }
    }
}