Skip to content

Inputs

An input is some knowledge about the game world that is used to calculate the score of a consideration. For example:

  • My health
  • Enemy’s health
  • Distance to the enemy

Creating Inputs

There are two ways to create a new input:

  1. Define a new class that inherits from Input<TValue> and override the OnGetRawInput funnction. For example:

    public class DistanceToTargetInput : Input<float>
    {
        protected override float OnGetRawInput(in InputContext context)
        {
            var currentPos = AgentFacade.Position;
            var targetPos = context.TargetFacade.Position;
            currentPos.Y = 0;
            targetPos.Y = 0;
    
            return Vector3.Distance(currentPos, targetPos);
        }
    }
    

  2. Define a new class that inherits from InputFromSource<TValue> and override the OnGetRawInput function.

    [Category("Examples")]
    public class HealthInput : InputFromSource<int>
    {
        protected override int OnGetRawInput(in InputContext context)
        {
            UtilityEntity inputSource = GetInputSource(in context);
            if (inputSource.EntityFacade is Character character)
            {
                return character.Health;
            }
    
            return 0;
        }
    }
    

    • This method allows you to set the source of the input to Self or Target.
      Attachments/UtilityIntelligence/Documentation/UtilityIntelligence/Considerations/Inputs/input-source.png
    • Note: Use this method only if the input exists in both Self and Target.

To add the input to the intelligence asset, go to the Input Tab, select the input type, give it a name, and then click the Create button:

center|400

To attach an input to an input normalization, select the input normalization in the Input Normalization Tab, and then choose the input’s name from the dropdown menu:

center|600

Note

Note: Only inputs with the same value type as the input normalization can be attached to it.

Adding Parameter Fields

There are many cases when you need to add parameters to an input to customize its return value. To achieve this, you need to declare these parameters as public fields in your inputs. Here are some examples of how to do this:

public abstract class InputFromSource<T> : Input<T>
{
    public InputSource InputSource;

    protected UtilityEntity GetInputSource(in InputContext context)
    {
        if (InputSource == InputSource.Self)
            return Agent;
        if (InputSource == InputSource.Target)
            return context.Target;

        return null;
    }
}
public abstract class BasicInput<T> : Input<T>
{
    public VariableReference<T> InputValue;
    protected override T OnGetRawInput(in InputContext context)
    {
        return InputValue.Value;
    }
}

Built-in Inputs

Currently, Utility Intelligence provides these buit-in inputs:

  • BasicInputFloatInt
  • BasicInputBool
  • BasicInputFloat
  • BasicInputDouble
  • BasicInputLong
  • BasicInputVector2
  • BasicInputVector3
  • BasicInputVector2Int
  • BasicInputVector3Int
    • Returns the value from its InputValue field, which can reference a variable in the Blackboard.
  • DistanceToTargetInput: Returns the distance from the current agent to the target.
  • CooldownElapsedTimeInput: Returns the elapsed time since the cooldown started.
  • RaycastToTargetInput: Returns true if the raycast hits the target; otherwise, returns false.

If you haven’t already, please consider leaving a review on the Asset Store. Whether good or bad, your feedback helps shape the future of this framework, and lets others determine whether it’s a good fit for their games. Thank you so much!💘 I love you all!🥰


Last update : October 10, 2025
Created : September 16, 2024