// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action. #include "GameFeatures/OLSGameFeatureAction_WorldActionBase.h" #include "GameFeaturesSubsystem.h" void UOLSGameFeatureAction_WorldActionBase::OnGameFeatureActivating(FGameFeatureActivatingContext& context) { // Don't call Super since we don't need it. GameInstanceStartHandles.FindOrAdd(context) = FWorldDelegates::OnStartGameInstance.AddUObject(this, &UOLSGameFeatureAction_WorldActionBase::HandleGameInstanceStart, FGameFeatureStateChangeContext(context)); // Add to any worlds with associated game instances that have already been initialized for (const FWorldContext& worldContext : GEngine->GetWorldContexts()) { if (context.ShouldApplyToWorldContext(worldContext)) { AddToWorld(worldContext, context); } } } void UOLSGameFeatureAction_WorldActionBase::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& context) { // Don't call Super since we don't need it. FDelegateHandle* foundHandle = GameInstanceStartHandles.Find(context); if (ensure(foundHandle)) { FWorldDelegates::OnStartGameInstance.Remove(*foundHandle); } } void UOLSGameFeatureAction_WorldActionBase::HandleGameInstanceStart(UGameInstance* gameInstance, FGameFeatureStateChangeContext changeContext) { if (FWorldContext* worldContext = gameInstance->GetWorldContext()) { if (changeContext.ShouldApplyToWorldContext(*worldContext)) { AddToWorld(*worldContext, changeContext); } } }