Unity-Technologies/ml-agents · critical · UnityAgentsException
Can't use Behavior Type {behaviorType} without a model. Eith
Error message
Can't use Behavior Type {behaviorType} without a model. Either assign a model, or change to a different Behavior Type. What it means
BehaviorParameters.GeneratePolicy() throws this when BehaviorType is set to InferenceOnly but no neural network model (m_Model) is assigned. Inference-only agents run entirely on a trained model, so without one there is no policy to create. The library demands either a model or a different behavior type that doesn't need one (e.g. HeuristicOnly).
Source
Thrown at com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs:240
}
void Awake()
{
OnPolicyUpdated += mode => { };
}
internal IPolicy GeneratePolicy(ActionSpec actionSpec, ActuatorManager actuatorManager)
{
switch (m_BehaviorType)
{
case BehaviorType.HeuristicOnly:
return new HeuristicPolicy(actuatorManager, actionSpec);
case BehaviorType.InferenceOnly:
{
if (m_Model == null)
{
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
}
return new SentisPolicy(actionSpec, actuatorManager, m_Model, m_InferenceDevice, m_BehaviorName, m_DeterministicInference);
}
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{
return new RemotePolicy(actionSpec, actuatorManager, FullyQualifiedBehaviorName);
}
if (m_Model != null)
{
return new SentisPolicy(actionSpec, actuatorManager, m_Model, m_InferenceDevice, m_BehaviorName, m_DeterministicInference);
}
else
{
return new HeuristicPolicy(actuatorManager, actionSpec);View on GitHub (pinned to 3ecb446f75)
Solutions
- Assign a trained model asset (.nn / ONNX) to the Model field of the BehaviorParameters component
- Change Behavior Type to Heuristic Only or Default (which falls back to heuristic) if you don't have a model yet
- Set the model programmatically via behaviorParameters.SetModel(behaviorName, model) before the Academy initializes
- Verify the model asset import succeeded (Sentis/Unity Inference Engine imported the ONNX) so the field isn't silently null
Example fix
// before behaviorParameters.behaviorType = BehaviorType.InferenceOnly; // Model left null // after behaviorParameters.behaviorType = BehaviorType.InferenceOnly; behaviorParameters.model = trainedModelAsset; // assigned .nn/ONNX model
Defensive patterns
Strategy: validation
Validate before calling
// Unity C#: before Academy init / first step
if (behaviorParameters.BehaviorType == BehaviorType.InferenceOnly && behaviorParameters.Model == null)
{
behaviorParameters.Model = trainedModelAsset; // or fall back to BehaviorType.HeuristicOnly
} Try / catch
try
{
academyInitialize();
}
catch (UnityAgentsException e) when (e.Message.Contains("without a model"))
{
behaviorParameters.BehaviorType = BehaviorType.HeuristicOnly;
} Prevention
- Always assign the .nn model asset in the inspector before entering Play mode
- Use BehaviorType.Default while iterating without a trained model
- Validate BehaviorParameters in an editor script for all agents in the scene
When it happens
Trigger: Setting a BehaviorParameters component's Behavior Type to 'Inference Only' while the Model field is left empty; assigning a model at runtime via SetModel() with a null model; clearing the model in code or via prefab overrides before academy initialization.
Common situations: Dropping a trained NN model out of the inspector and forgetting to reassign; a training run failed so the .nn file was never produced; switching from Heuristic Only to Inference Only to test inference but never wiring up the model asset; prefab variants inheriting from a base that had no model.
Related errors
- Action spaces with both continuous and discrete actions are
- The number of training areas that you have specified exceeds
- Unknown tensorProxy expected as output : {tensor.name}
- Sensor {sensor.GetName()} have an invalid rank {rank}
- Unknown tensorProxy expected as input : {tensor.name}
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/bd3dd850b34f53ab.
Report an issue: GitHub.