|
21 | 21 | #include "Modules/ModuleManager.h"
|
22 | 22 | #endif
|
23 | 23 |
|
24 |
| -/*static*/ UObject* ACesiumCreditSystem::CesiumCreditSystemBP = nullptr; |
25 | 24 | namespace {
|
26 | 25 |
|
27 | 26 | /**
|
@@ -89,22 +88,6 @@ FName ACesiumCreditSystem::DEFAULT_CREDITSYSTEM_TAG =
|
89 | 88 |
|
90 | 89 | /*static*/ ACesiumCreditSystem*
|
91 | 90 | ACesiumCreditSystem::GetDefaultCreditSystem(const UObject* WorldContextObject) {
|
92 |
| - // Blueprint loading can only happen in a constructor, so we instantiate a |
93 |
| - // loader object that retrieves the blueprint class in its constructor. We can |
94 |
| - // destroy the loader immediately once it's done since it will have already |
95 |
| - // set CesiumCreditSystemBP. |
96 |
| - if (!IsValid(CesiumCreditSystemBP)) { |
97 |
| - UCesiumCreditSystemBPLoader* bpLoader = |
98 |
| - NewObject<UCesiumCreditSystemBPLoader>(); |
99 |
| - CesiumCreditSystemBP = bpLoader->CesiumCreditSystemBP.LoadSynchronous(); |
100 |
| - // Prevent the GC from destroying the object when unloading a level, as it will be reused |
101 |
| - // if one subsequently loads another level. This kind of static object should probably be |
102 |
| - // replaced by a "subsystem" |
103 |
| - // (https://dev.epicgames.com/documentation/en-us/unreal-engine/programming-subsystems-in-unreal-engine) |
104 |
| - CesiumCreditSystemBP->AddToRoot(); |
105 |
| - bpLoader->ConditionalBeginDestroy(); |
106 |
| - } |
107 |
| - |
108 | 91 | UWorld* world = WorldContextObject->GetWorld();
|
109 | 92 | // This method can be called by actors even when opening the content browser.
|
110 | 93 | if (!IsValid(world)) {
|
@@ -159,8 +142,11 @@ ACesiumCreditSystem::GetDefaultCreditSystem(const UObject* WorldContextObject) {
|
159 | 142 | spawnParameters.SpawnCollisionHandlingOverride =
|
160 | 143 | ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
161 | 144 | spawnParameters.OverrideLevel = world->PersistentLevel;
|
162 |
| - pCreditSystem = world->SpawnActor<ACesiumCreditSystem>( |
163 |
| - Cast<UClass>(CesiumCreditSystemBP), |
| 145 | + UCesiumCreditSystemBPLoader* bpLoader = |
| 146 | + GEngine->GetEngineSubsystem<UCesiumCreditSystemBPLoader>(); |
| 147 | + UClass* CesiumCreditSystemBP = |
| 148 | + Cast<UClass>(bpLoader->CesiumCreditSystemBP.LoadSynchronous()); |
| 149 | + CesiumCreditSystemBP, |
164 | 150 | spawnParameters);
|
165 | 151 | // Null check so the editor doesn't crash when it makes arbitrary calls to
|
166 | 152 | // this function without a valid world context object.
|
|
0 commit comments