Created
May 21, 2020 21:39
-
-
Save Erlite/2853d8b9d86c6efecdadc2072b2927f4 to your computer and use it in GitHub Desktop.
Simple way to grab blueprint components from a CDO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Room.cpp | |
void ARoom::SetupDefaultObject(UBlueprintGeneratedClass* BlueprintClass) | |
{ | |
checkf(HasAnyFlags(RF_ClassDefaultObject), TEXT("ARoom::SetupDefaultObject() can only be called on ARoom default objects.")); | |
checkf(BlueprintClass, TEXT("Cannot setup default room object with null blueprint class.")); | |
if (bIsDefaultSetup) return; | |
TArray<const UBlueprintGeneratedClass*> BlueprintClasses; | |
UBlueprintGeneratedClass::GetGeneratedClassesHierarchy(BlueprintClass, BlueprintClasses); | |
for (const UBlueprintGeneratedClass* Class : BlueprintClasses) | |
{ | |
if (Class->SimpleConstructionScript) | |
{ | |
TArray<USCS_Node*> CDONodes = Class->SimpleConstructionScript->GetAllNodes(); | |
for (USCS_Node* Node : CDONodes) | |
{ | |
UActorComponent* CDOComponent = Node->GetActualComponentTemplate(Cast<UBlueprintGeneratedClass>(BlueprintClass)); | |
if (URoomEmplacementComponent* Emplacement = Cast<URoomEmplacementComponent>(CDOComponent)) | |
{ | |
DefaultObjectEmplacements.Add(Emplacement->GetEmplacementName(), Emplacement); | |
} | |
} | |
} | |
} | |
bIsDefaultSetup = true; | |
} | |
TArray<URoomEmplacementComponent*> ARoom::GetRoomEmplacements() const | |
{ | |
TArray<URoomEmplacementComponent*> EmplacementComponents; | |
if (HasAnyFlags(RF_ClassDefaultObject)) | |
{ | |
checkf(bIsDefaultSetup, TEXT("Attempted to get room emplacements from CDO, but it wasn't setup.")); | |
DefaultObjectEmplacements.GenerateValueArray(EmplacementComponents); | |
} | |
else | |
{ | |
RegisteredEmplacements.GenerateValueArray(EmplacementComponents); | |
} | |
return EmplacementComponents; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment