Nelaric Unreal Gameplay
Gameplay framework API
Loading...
Searching...
No Matches
InitStateWorldSubsystem.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric
2
6
7#pragma once
8
9#include "Containers/Array.h"
10#include "Containers/Set.h"
11#include "Containers/Map.h"
12#include "Subsystems/WorldSubsystem.h"
13#include "UObject/WeakObjectPtr.h"
14#include "Pawn/InitStateTypes.h"
15
16#include "InitStateWorldSubsystem.generated.h"
17
18class UActorComponent;
19class AActor;
20
21namespace Nelaric
22{
28{
30 UActorComponent* Component = nullptr;
31
34
37
39 TArray<UActorComponent*> Dependencies;
40};
41} // namespace Nelaric
42
49UCLASS(MinimalAPI)
50class UInitStateWorldSubsystem : public UWorldSubsystem
51{
52 GENERATED_BODY()
53
54public:
58 GAMEPLAYRUNTIME_API void RegisterParticipant(UActorComponent* Component);
59
63 GAMEPLAYRUNTIME_API void UnregisterParticipant(UActorComponent* Component);
64
69 GAMEPLAYRUNTIME_API void NotifyParticipantChanged(UActorComponent* Component,
70 const Nelaric::FInitStateSnapshot& Previous);
71
76 GAMEPLAYRUNTIME_API void RequestParticipantRefresh(UActorComponent* Component);
77
89 GAMEPLAYRUNTIME_API bool ConfigureParticipant(UActorComponent* Component, FName ComponentId,
90 bool bRequiredForPawnReady,
91 const TArray<UActorComponent*>& Dependencies);
92
100 GAMEPLAYRUNTIME_API bool
101 ConfigureParticipants(const TArray<Nelaric::FInitParticipantConfiguration>& Configurations);
102
109 GAMEPLAYRUNTIME_API bool AreRequiredParticipantsReady(const AActor* Owner) const;
110
115 GAMEPLAYRUNTIME_API bool IsParticipantReady(UActorComponent* Component) const;
116
117public:
118 virtual void Deinitialize() override;
119
120private:
121 friend class UPawnInitializationComponent;
122 bool HasConfiguredId(const AActor* Owner, FName ComponentId) const;
123 void StopConfiguredParticipants(const TArray<UActorComponent*>& Components);
124 using FComponentPtr = TWeakObjectPtr<UActorComponent>;
125 TSet<FComponentPtr> RegisteredComponents;
126 TSet<FComponentPtr> StoppedComponents;
127 bool bShuttingDown = false;
128 struct FConfiguredParticipant
129 {
130 TWeakObjectPtr<AActor> Owner;
131 FName ComponentId;
132 bool bRequiredForPawnReady = true;
133 TArray<FComponentPtr> Dependencies;
134 };
135 TMap<FComponentPtr, FConfiguredParticipant> ConfiguredComponents;
136 TMap<FComponentPtr, TArray<FComponentPtr>> ForwardDependencies;
137 TMap<FComponentPtr, TArray<FComponentPtr>> ReverseDependencies;
138 TMap<TWeakObjectPtr<AActor>, TArray<FComponentPtr>> RequiredByOwner;
139 TMap<FComponentPtr, int32> ReadyGroupByComponent;
140 TArray<TArray<FComponentPtr>> ReadyGroups;
141 uint64 GraphVersion = 0;
142 int32 GraphEdgeCount = 0;
143 TArray<FComponentPtr> PendingQueue;
144 TSet<FComponentPtr> QueuedComponents;
145 TSet<TWeakObjectPtr<AActor>> PendingOwners;
146 bool bProcessing = false;
147 bool bInvalidatingDependents = false;
148 void RebuildDependencyGraph();
149 void QueueParticipant(UActorComponent* Component);
150 void QueueParticipantAndDependents(UActorComponent* Component);
151 void QueueAllRegistered();
152 void ProcessParticipants();
153 bool TryCommitReadyGroup(UActorComponent* Root);
154 void InvalidateConfiguredDependents(UActorComponent* Component);
155};
Coordinates registered initialization participants in one world.
Definition InitStateWorldSubsystem.h:51
GAMEPLAYRUNTIME_API void RequestParticipantRefresh(UActorComponent *Component)
Rechecks a registered participant after its context changes.
GAMEPLAYRUNTIME_API void UnregisterParticipant(UActorComponent *Component)
Removes a participant before it leaves the world.
GAMEPLAYRUNTIME_API bool AreRequiredParticipantsReady(const AActor *Owner) const
Checks the configured required participants of an actor.
GAMEPLAYRUNTIME_API void NotifyParticipantChanged(UActorComponent *Component, const Nelaric::FInitStateSnapshot &Previous)
Reports a component-owned state or generation change.
GAMEPLAYRUNTIME_API bool ConfigureParticipants(const TArray< Nelaric::FInitParticipantConfiguration > &Configurations)
Installs a resolved local dependency graph in one update.
GAMEPLAYRUNTIME_API bool ConfigureParticipant(UActorComponent *Component, FName ComponentId, bool bRequiredForPawnReady, const TArray< UActorComponent * > &Dependencies)
Installs the manager's immutable configuration for a component.
GAMEPLAYRUNTIME_API bool IsParticipantReady(UActorComponent *Component) const
Checks a configured participant's current Ready state.
GAMEPLAYRUNTIME_API void RegisterParticipant(UActorComponent *Component)
Registers a reflected participant and attempts progress.
One resolved, local participant and its Ready dependencies.
Definition InitStateWorldSubsystem.h:28
TArray< UActorComponent * > Dependencies
Local Ready dependencies; cyclic peers commit together.
Definition InitStateWorldSubsystem.h:39
bool bRequiredForPawnReady
Whether pawn readiness includes this component.
Definition InitStateWorldSubsystem.h:36
UActorComponent * Component
Component owned by the local actor.
Definition InitStateWorldSubsystem.h:30
FName ComponentId
Stable ID unique on the actor.
Definition InitStateWorldSubsystem.h:33
Captures the stage and terminal failure of one initialization attempt.
Definition InitStateTypes.h:41