Vixen
02b45cc4
csharp
public sealed class BehaviorRegistrationGenerator

Declares every behaviour this assembly can put in a scene, before any of its code runs.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

ComponentRegistrationGenerator's twin, keyed off [DataContract] rather than [Component]. A behaviour is a class and carries no [Component] — the ECS never attaches it to an entity, BehaviorStore does — so what declares one authorable is that it is a Behavior and that it can be described. Both halves are necessary: a behaviour with no contract is one a scene could name and not restore, which is worse than one it cannot name.

⚠ Started from the attribute rather than from the base type, because that is what an incremental generator can index. ForAttributeWithMetadataName is driven by a table the compiler already keeps; asking "does this class derive from Behavior" over every type in the compilation is a walk per keystroke. The base-type check is then a cheap filter on the handful of types that carry the attribute at all.

⚠ A behaviour needs a public parameterless constructor, and the diagnostic says so. The registry's Declare<T> is constrained new() because the editor makes one when somebody adds it and the loader makes one before it fills it in. A behaviour whose only constructor takes arguments is perfectly good code and is not authorable, and the difference is worth a message rather than a build error somewhere else.

Methods (1)

  • public void Initialize(IncrementalGeneratorInitializationContext context)

    Called to initialize the generator and register generation steps via callbacks on the