Skip to content

[Feature]: On-Demand Singletons #321

Description

Feature Description

Control whether singletons are auto-created or not through attributes! Something like this:

using System;

/// <summary>
/// Marks a <see cref="SingletonBehaviour{T}"/> that is allowed to be created on demand when no
/// instance exists in any loaded scene.
/// </summary>
/// <remarks>
/// Only valid for singletons that hold no serialized state, because a runtime-created instance is a
/// bare component with every [SerializeField] left null. Anything authored in a scene or prefab must
/// NOT carry this attribute - for those, a missing instance is a load-order bug and needs to be loud
/// rather than papered over with a stand-in that silently behaves like the real thing.
/// </remarks>
[AttributeUsage(AttributeTargets.Class, Inherited = true)] 
public sealed class RuntimeCreatableSingletonAttribute : Attribute
{
}

Use Case / Motivation

Sometimes people don't want auto-loading singletons. If we don't have this kind of behavior, we should add it (or, make it configurable in other ways)

Proposed Solution

The attribute thing, or an overridable property, or similar

Alternatives Considered

No response

Unity Version

None

Package Version

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions