Unity-Technologies/UnityCsReference · error · ArgumentException

Abstract types can't be used in the ObjectFactory : {type.Fu

Error message

Abstract types can't be used in the ObjectFactory : {type.FullName}

What it means

Thrown by ObjectFactory.CheckTypeValidity when type.IsAbstract is true. Abstract types cannot be instantiated, so ObjectFactory refuses to create them.

Source

Thrown at Editor/Mono/ObjectFactory.bindings.cs:51

        [FreeFunction]
        static extern GameObject CreateDefaultGameObject(string name);

        [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);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Pass a concrete (non-abstract) Type to CreateInstance.
  2. Resolve the abstract type to a concrete subclass before invoking.
  3. Guard with !type.IsAbstract before calling.

Example fix

// before
ObjectFactory.CreateInstance(typeof(MyAbstractBase));
// after
ObjectFactory.CreateInstance(typeof(MyConcreteDerived));
Defensive patterns

Strategy: validation

Validate before calling

if (!type.IsAbstract) ObjectFactory.CreateInstance(type);

Type guard

static bool IsInstantiable(Type t) => !t.IsAbstract && !t.IsInterface;

Prevention

When it happens

Trigger: Calling ObjectFactory.CreateInstance with an abstract Type (e.g., typeof(ScriptableObject) itself, or an abstract MonoBehaviour subclass).

Common situations: Generic factory code passing a runtime Type that resolves to an abstract base; reflection picking the base instead of a concrete subclass.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/167c566c27240245. Report an issue: GitHub.