Get a reference to component owner while in blueprint editor

For anyone Googling this, I found my solution here: Actor.GetComponents() returns Null for blueprint generated actor - #8 by M.Haenssgen

In the editor, the component has no owner, but you can use the the blueprint generated class outer, which leads you to the “nodes” (aka components).

	TArray<FString> options;

	UBlueprintGeneratedClass* owningGenClass = Cast<UBlueprintGeneratedClass>(GetOuter());
	if (owningGenClass == nullptr)
	{
		return options;
	}
	const TObjectPtr<USimpleConstructionScript> constructionScript = owningGenClass->SimpleConstructionScript;
	if (constructionScript == nullptr)
	{
		return options;
	}
	for (const USCS_Node* component : constructionScript->GetAllNodes())
	{
		const UMeshComponent* meshComponent = Cast<UMeshComponent>(component->ComponentTemplate);
		if (meshComponent != nullptr)
		{
			FName name = component->GetVariableName();
			if ( ! meshComponents.Contains(name))
			{
				options.Add(name.ToString());
			}
		}
	}
	return options;
2 Likes