Declares a method to create instances in place of the default constructor.
Use this to provide custom instance creation logic, such as object pooling or dependency injection. The method must meet the following requirements:
If this attribute is not found on the element, the source generator uses the default constructor (new T()).
If the method returns null, the source generator uses the default constructor as a fallback.
The following example uses a custom creation method for object pooling:
using UnityEngine.UIElements; using UnityEngine.Pool;
namespace MyNamespace { [UxmlElement] public partial class MyButtonElement : Button { [UxmlCreateInstanceMethodAttribute] public static MyButtonElement CreateInstance() { return GenericPool<MyButtonElement>.Get(); } } }