Skip to content

Custom responses and condition policies

Use SystemBasedObject to apply Tunal influence to your own object type. Keep simulation querying and effect application separate so existing Inspector conditions can drive the same response.

Create a response

Create a script named InfluenceCanvas.cs, attach it to a UI GameObject with a CanvasGroup, assign its context/conditions, and enter Play Mode:

InfluenceCanvas.cs
using Sital.Tunal.Objects;
using UnityEngine;

namespace TunalExamples
{
    [DefaultExecutionOrder(5000)]
    [RequireComponent(typeof(CanvasGroup))]
    public sealed class InfluenceCanvas : SystemBasedObject
    {
        private CanvasGroup target;

        protected override void ApplyInfluence(float influence, bool immediate)
        {
            if (target == null) target = GetComponent<CanvasGroup>();
            target.alpha = influence;
            target.interactable = influence >= 0.5f;
            target.blocksRaycasts = influence >= 0.5f;
        }
    }
}

The required override is ApplyInfluence(float influence, bool immediate), not an imagined OnInfluenceChanged hook. The base calls it in Play Mode as normalized output changes or an immediate refresh is requested. The example retains the supplied responses' execution order so dependent simulation has evaluated before application.

Do not override Unity callbacks merely to repeat base binding. If you do override OnEnable, OnDisable, OnValidate, or LateUpdate, call the base behavior appropriately or you will lose subscription, cleanup, or evaluation. Keep the host enabled; change the target effect rather than deactivating the updater.

For continuously moving targets, RequiresContinuousApplication requests application even at unchanged influence. ReapplyWhenDirty, AdditionalSourcesMask, and UsesActivationConditions are specialized protected contracts used by the supplied data-driven responses. Prefer the simple override until you actually need independent source subscriptions or continuous state.

Customer-defined conditions

SystemCondition is a sealed, value-only serialized type; the supplied Inspector dispatches through fixed source/metric enums. There is no public virtual evaluator registry or polymorphic condition list. Do not subclass it, add enum values in customer code, or describe a new ScriptableObject condition as automatically discoverable.

Instead, evaluate customer gameplay rules in a separate component and use the supported manual-input API:

GameplayInfluence.cs
using Sital.Tunal.Objects;
using UnityEngine;

namespace TunalExamples
{
    public sealed class GameplayInfluence : MonoBehaviour
    {
        [SerializeField] private SystemBasedObject response;

        public void SetGameplayAllowed(bool allowed)
        {
            if (response == null) return;
            response.SetAutomated(false);
            response.SetManualInfluence(allowed ? 1f : 0f);
        }
    }
}

Call SetGameplayAllowed from your gameplay code or a compatible event. Once manual mode is selected, the response's Inspector conditions no longer determine activation; combine your complete custom predicate in the driver. To return to configured Tunal conditions call SetAutomated(true).

If your predicate also needs time or season state, bind to the chosen context and query its initialized systems. Do not access private serialized condition fields through reflection or allocate a new polling condition object per frame. Add explicit subscribe/unsubscribe logic if your policy consumes system events.

These examples demonstrate public contracts and pass standalone compilation against the current runtime source. Inspector wiring and Play Mode behavior still require Unity validation. They do not alter Tunal runtime code.

Related: condition semantics, API contracts.