Code inspection: To use the result of a 'GetSingleton' call in the function, 'OnCreate' must include a 'RequireForUpdate' call
This inspection reports SystemAPI.GetSingleton<T>() and GetSingletonEntity<T>() calls in ISystem code when the system's OnCreate method does not request the singleton with RequireForUpdate.
Without RequireForUpdate<T>(), the system can run even when the singleton is missing, which makes the singleton access unsafe.
Example
In this example, GetSingleton<GameConfig>() is called, but the system has not required GameConfig for update. The quick-fix adds the missing requirement to OnCreate.
using Unity.Entities;
public partial struct ExampleSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
// Reported: singleton must be requested with RequireForUpdate
var config = SystemAPI.GetSingleton<GameConfig>();
}
}
using Unity.Entities;
public partial struct ExampleSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<GameConfig>();
}
public void OnUpdate(ref SystemState state)
{
var config = SystemAPI.GetSingleton<GameConfig>();
}
}
Quick-fix
Use the quick-fix to add the missing RequireForUpdate<T>() call for the singleton type, or to add all missing singleton requirements at once.
If there is no OnCreate method, the quick-fix creates one. If OnCreate already exists, it inserts the missing request there.
26 March 2026