Unity-Technologies/UnityCsReference · error · ArgumentException
The type {type.FullName} is not supported by the ObjectFacto
Error message
The type {type.FullName} is not supported by the ObjectFactory. What it means
Thrown by ObjectFactory.CheckTypeValidity when the type is decorated with ExcludeFromObjectFactoryAttribute. Such types are explicitly excluded from the factory's creation path (typically created through specialized APIs instead).
Source
Thrown at Editor/Mono/ObjectFactory.bindings.cs:55
[AutoStaticsCleanupOnCodeReload]
public static event Action<Component> componentWasAdded;
[RequiredByNativeCode]
static void InvokeComponentWasAdded(Component component)
{
if (componentWasAdded != null)
componentWasAdded(component);
}
static void CheckTypeValidity(Type type)
{
if (type.IsAbstract)
{
throw new ArgumentException("Abstract types can't be used in the ObjectFactory : " + type.FullName);
}
if (Attribute.GetCustomAttribute(type, typeof(ExcludeFromObjectFactoryAttribute)) != null)
{
throw new ArgumentException("The type " + type.FullName + " is not supported by the ObjectFactory.");
}
}
public static T CreateInstance<T>() where T : Object
{
return (T)CreateInstance(typeof(T));
}
public static Object CreateInstance(Type type)
{
CheckTypeValidity(type);
if (type == typeof(GameObject))
{
throw new ArgumentException("GameObject type must be created using ObjectFactory.CreateGameObject instead : " + type.FullName);
}
if (type.IsSubclassOf(typeof(Component)))
{
throw new ArgumentException("Component type must be created using ObjectFactory.AddComponent instead : " + type.FullName);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Do not use ObjectFactory for the excluded type — use its dedicated creation API.
- Remove ExcludeFromObjectFactoryAttribute if the type should be factory-created (rare; usually intentional).
- Skip excluded types when iterating.
Example fix
// before
ObjectFactory.CreateInstance(typeof(ExcludedType));
// after: use the type's intended creation path, or filter
if (Attribute.GetCustomAttribute(t, typeof(ExcludeFromObjectFactoryAttribute)) == null)
ObjectFactory.CreateInstance(t); Defensive patterns
Strategy: type-guard
Validate before calling
if (Attribute.GetCustomAttribute(type, typeof(ExcludeFromObjectFactoryAttribute)) == null)
ObjectFactory.CreateInstance(type); Type guard
static bool IsFactorySupported(Type t) =>
Attribute.GetCustomAttribute(t, typeof(ExcludeFromObjectFactoryAttribute)) == null; Prevention
- Respect ExcludeFromObjectFactoryAttribute in iteration.
- Use the type's dedicated creation API when excluded.
When it happens
Trigger: Calling ObjectFactory.CreateInstance on a Type marked [ExcludeFromObjectFactory].
Common situations: Type is meant to be created only by the engine; user code tries to factory-instantiate it. Code-generation template iterates all types without respecting the attribute.
Related errors
- Abstract types can't be used in the ObjectFactory : {type.Fu
- GameObject type must be created using ObjectFactory.CreateGa
- Component type must be created using ObjectFactory.AddCompon
- Non-Component type must use ObjectFactory.CreateInstance ins
- Cannot create a GameObject to a null Scene.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/eaca3fddb537c1d0.
Report an issue: GitHub.