GetChildrenComponents not working inside editor details customization

I’m currently using the Unreal Engine 4.9 due to compiler restrictions. New compiler is on the way but wont be here until next week.

I am working on performing DetailsCustomization work to override the behavior of the details panel for a specific actor class. The details customization works as it should. Where I am running into a problem is when I need to obtain a list of components attached to the blueprint derived class inside the editor.

	//Extract all hardpoint components from character and enter into list to be returned
	if (RootComponent != nullptr)
	{
		TArray<UActorComponent *> children=GetComponents();
		for (UActorComponent * child : children)
		{
			hardpointList.Add(MakeShareable(new FString(child->GetName())));

			USceneComponent *sceneComp = Cast<USceneComponent>(child);
			if (sceneComp != nullptr)
			{
				TArray<USceneComponent *> grandchildren;
				sceneComp->GetChildrenComponents(true, grandchildren);
				for (USceneComponent *grandchild : grandchildren)
				{
					hardpointList.Add(MakeShareable(new FString(grandchild->GetName())));
				}
			}
		}
	}

This is an image of our current character configuration inside the Unreal Editor 4.9.
GetChidlrenComponents always returns an empty array from the first level of components.

Any suggestions as to how to obtain the components prefixed with ‘wh’?

CDOs have no components. Annoying, yes.

If the components you’re looking for belong to the CDO you’re using (i.e., aren’t inherited form another class) you can get the components on the CDO by casting the CDO Actor to a BlueprintGeneratedClass, call GetAllNodes() to get an array of USCS_Nodes. Each of these will contain a template of the components on the CDO in its “Template” member.

This isn’t going to work. We are using version 4.9.2 due to compiler restictions at this time. Later we’ll be upgrading to version 4.15 or the newest at that time.

Under 4.9.2, there is no GetAllNodes method under UBlueprintGeneratedClass or any of its parent classes. The only method I can find is USMC::GetAllNodes(). Is this the method you’re referring to?

The final solution to finding a list of attached components in the editor during customizing details panel:

Obtain a reference to the UClass representing the object you are customizing.
Cast this to UBlueprintGeneratedClass, ( Cast(‘your UClass pointer’) )
if cast succeeds then call ‘blueprint generated class’ construction script member’s GetAllNodes() to obtain a list of USCS_Nodes attached to this class. The list of USCS_Nodes represent each component attached to the editor object and can provide the data desired from the components within the editor through its ComponentTemplate member.

NOTE: This only lists immediate components added to the blueprint class. Any inherited components will not show up in this list.

Below is the code for performing this. It only extract the human readable name of the component, aka variable name.

void AMechCharacter::GetHardpointList(TArray<TSharedPtr<FString>>& hardpointList)
{
	//Clear list
	hardpointList.Empty();

	//Get character class for this object
	UClass *mechClass = GetClass();
	if (mechClass != nullptr)
	{
		//Cast to UBlueprointGeneratedClass
		UBlueprintGeneratedClass *blueprintClass = Cast<UBlueprintGeneratedClass>(mechClass);
		if (blueprintClass != nullptr)
		{
			//Extract all USCS_Node from the SimpleConstructionScript member of the blueprint generated class
			TArray<USCS_Node *> rootNodes=blueprintClass->SimpleConstructionScript->GetAllNodes();
			for (USCS_Node *node : rootNodes)
			{
				if (node->ComponentTemplate != nullptr)
				{
					//Extract information from the ComponentTemplate member of the USCS_Node object
					FString nodeName = node->ComponentTemplate->GetName();
					UClass *nodeClass = node->ComponentTemplate->GetClass();
					if (nodeClass->IsChildOf(UWeaponHardpointComponent::StaticClass()))
					{
						//Extract Component name from nodeName - by removing characters after '_GEN_'
						int offset = nodeName.Find(FString("_GEN_"));
						if (offset > 0)
						{
							FString hardpointName = nodeName.LeftChop(nodeName.Len() - offset);
							hardpointList.Add(MakeShareable(new FString(hardpointName)));
						}
					}
				}
			}
		}
	}
}

Sorry, I missed a step. It’s been a little while since I had to do this.

On the UBlueprintGeneratedClass, there’s a USimpleConstructionScript called SimpleConstructionScript. It’s what has the GetAllNodes() function to return the array of USCS_Nodes.

I can’t promise that’s the case in 4.9.2, I don’t have that build and there seems to be no way to look back at previous verisons in the API documentation website. But that’s a pretty low-level system so it shouldn’t have changed much.

Its alright. We all do at times. You put me in the right direction and I’m very thankful for that. This code is from 4.9.2.

Thank you very much.

What do you do if you need to get those inherited components as well?