Skip to content

Commit 2180074

Browse files
committed
Hybrid subsystem info, getting subsystems in C++, Wait for Subsystem
1 parent cd4266c commit 2180074

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

modules/ROOT/pages/Development/ModLoader/Subsystems.adoc

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ If you're implementing a subsystem in {cpp} and you override BeginPlay or EndPla
3333
be sure to call the super functions, or the subsystem will not be handled correctly!
3434
====
3535

36+
=== Hybrid Subsystems
37+
38+
Subsystems can be a convenient place to implement hybrid Blueprint and {cpp} functionality
39+
since they can be easily retrieved from anywhere with world context.
40+
To do this, define your subsystem in {cpp} with `UCLASS(Abstract, Blueprintable)`
41+
then create a Blueprint child class in the editor.
42+
Only the blueprint child class should be listed in the `Mod Subsystems` array of a Game World Module.
43+
44+
The following UFUNCTION specifiers are useful for hybrid subsystems:
45+
46+
- Implementing functions in {cpp} that can be called from Blueprints: `BlueprintCallable`, `BlueprintNativeEvent`
47+
- Implementing functions in Blueprints that can be called from {cpp}: `BlueprintImplementableEvent`, `BlueprintNativeEvent`
48+
3649
== Replication Policy
3750

3851
A subsystem's replication policy determines which side(s) the subsystem will exist on in multiplayer
@@ -42,7 +55,7 @@ Subsystems have the `SpawnOnServer` replication policy by default,
4255
meaninging clients do not have an instance of the subsystem.
4356
If this is not the desired behavior,
4457
review the table below to find the replication policy that best suits your needs,
45-
then change it in the Class Defaults (blueprint) or constructor (C++).
58+
then change it in the Class Defaults (Blueprint) or constructor ({cpp}).
4659

4760
.Replication Policy Quick Reference: Sidedness
4861
|===
@@ -99,15 +112,39 @@ make sure that you have correctly configured its Replication Policy.
99112

100113
== Referencing a Subsystem
101114

102-
A subsystem itself is an actor inheriting from `ModSubsystem`.
103-
You can also use subsystems to store data to save states.
104-
105115
Subsystems are held by the `SubsystemActorManager` that can be obtained using the `GetSubsystemActorManager` function.
106116
Use the `GetSubsystemActor` function on the manager to get a reference to a subsystem.
107117

118+
Consider checking if the retrieved subsystem is valid before trying to do anything with it using an IsValid node.
119+
120+
=== From Blueprints
121+
108122
image:Satisfactory/Subsystems/Subsystems_sam.PNG[GameWorldModule]
109123

110124
* The first parameter of the function is a reference to a `SubsystemActorManager` acquired using the `GetSubsystemActorManager` function.
111125
* The second parameter is the class of the subsystem actor to retrieve.
112126

113-
Consider checking if the retrieved subsystem is valid before trying to do anything with it.
127+
=== From {cpp}
128+
129+
The SubsystemActorManager is a UWorldSubsystem and as such can be accessed from the world context via Unreal's getter.
130+
GetSubsystemActor can be used with a generic type parameter to retrieve the subsystem actor of the specified class.
131+
132+
```cpp
133+
// Requires something with world context, for example, an actor
134+
UWorld* WorldObject = GEngine->GetWorldFromContextObjectChecked(WorldContext);
135+
USubsystemActorManager* SubsystemActorManager = WorldObject->GetSubsystem<USubsystemActorManager>();
136+
check(SubsystemActorManager);
137+
138+
AYourSubsystem* subsystem = SubsystemActorManager->GetSubsystemActor<AYourSubsystem>()
139+
```
140+
141+
Make sure to only use subsystems from the game thread.
142+
143+
== Wait for Subsystem
144+
145+
Although subsystems spawn relatively early in the game world loading sequence,
146+
sometimes code that wants to use them may end up triggering sooner.
147+
This can happen in multiplayer when a subsystem has not replicated to the client yet,
148+
or on hosts when an xref:Development/ModLoader/ActorMixins.adoc[Actor Mixin] is triggering code on Begin Play.
149+
150+
In these situations, you can use the `Wait for Subsystem` node in Blueprint event graphs to wait until the subsystem is available.

0 commit comments

Comments
 (0)