How to get GetSelectedComponents to work

Hi, I am writing a C++ plugin.
I am having a real difficult time trying to figure out why this code bellow, works.

TArray<AActor*> actors;
USelection* const selectedActors = GEditor->GetSelectedActors();
selectedActors->GetSelectedObjects(actors);
for (int i = actors.Num() - 1; i >= 0; --i)
{
	const MyCLass* const obj = Cast<MyCLass>(actors[i]);
	if (obj)
	{
		obj->DrawGizmo();
	}
}

but this one bellow, fails.

TArray<UActorComponent*> components;
USelection* const selectedComponets = GEditor->GetSelectedComponents();
selectedComponets->GetSelectedObjects(components);
for (int i = components.Num() - 1; i >= 0; --i)
{
	const MyCLass* const obj = Cast<MyCLass>(components[i]);
	if (obj)
	{
		obj->DrawGizmo();
	}
}

of course I can display the feedback for all components on the selected actor, but this could get clustered if there are a few components close together.
I would be nice if the use can visualize only the selected components.

I knwo this operation does not seems to work in the Level and scene editor, and that is fine.
But I knwo that selecting one or more component at a time when putting together a complet actor in teh blueprint editor. and it is here where thsi is important , when teh use is designing a complex actor, with more than one static scene component.

any answer on this, would be appreciated.
Julio.

The template type is probably not defined correctly.You need to start debugging in Visual Studio if you want to check.
I have always used this method

GetSelectedObjects(Class, Array)

and it has always worked.
It returns a list of components that are selected in the actor at the level.

I am using visual studio, the funtion prototype is define in file:
C:\Program Files\Epic Games\UE_5.4\Engine\Source\Editor\UnrealEd\Classes\Editor\EditorEngine.h
as

/**---|---
* @return the set of selected components.
*/
UNREALED_API class USelection* GetSelectedComponents() const;

as far as I can see there are not other definition of and that function that take any arguments,
or I can see any template version of it.
In any case, can you show a context of how to use it it properly.

Julio

TArray<UObject*> Buffer;
GEditor->GetSelectedComponents()->GetSelectedObjects(UMyClass::StaticClass(), Buffer);

for(UObject* Item: Buffer)
{
     UMyClass* Component = Cast<UMyClass>(Item);
     /*Some Actions*/
}

thank you.

I past that in my code like the code bellow.

void FnewtonModule::DrawGizmo() const
{
	TArray<AActor*> actors;
	USelection* const selectedActors = GEditor->GetSelectedActors();
	selectedActors->GetSelectedObjects(actors);
	for (int i = actors.Num() - 1; i >= 0; --i)
	{
		// this works, but draw all of the child component of in the actor
		const TSet<UActorComponent*>& components = actors[i]->GetComponents();
		for (TSet<UActorComponent*>::TConstIterator it(components.CreateConstIterator()); it; ++it)
		{
			const UNewtonStaticMeshComponent* const meshComp = Cast<UNewtonStaticMeshComponent>(*it);
			if (meshComp)
			{
				meshComp->DrawGizmo();
			}
		}
	}

	// ideally, we only want to draw debug for only the selected components in th editor
	// unfortunately some is no right, and this does not works.
	TArray<UObject*> selectedComponents;
	GEditor->GetSelectedComponents()->GetSelectedObjects(UActorComponent::StaticClass(), selectedComponents);
	for (int i = selectedComponents.Num() - 1; i >= 0; --i)
	{
		const UNewtonStaticMeshComponent* const meshComp = Cast<UNewtonStaticMeshComponent>(Buffer[i]);
		if (meshComp)
		{
			meshComp->DrawGizmo();
		}
	}
}

it does compile, but unfortunately is does not works either.
I actually did a global search in the engine and could not find a single instance where the function is use like that. in fact at least in the core engine, in all cases, it uses the version I was using.

The way I see it, that function is just a filter that iterates over the objects found by
GEditor->GetSelectedComponents(), it will not find anythong is GetSelectedComponents fails to select anything.

I know it works, I just do not knwo what it is that I am missing,

thank you

Are we sure we’re talking about the same thing?
The function returns a list of components that were selected like this:

yes we are.
I just find out why I though is was no working.

In teh editor, when the user select an actor, It seem teh actor and all it baggage is all selected, regardless of what actor component click on teh screen.

so select a specific component, the use has to go to teh outliner of any other browser and select that specific component.

this was why it seems it was failing, it is actually very nice.

this issues can be close now.
thanks for the help.

Julio