How to delete a specific actor when you click on a random actor?

Hello guys, I’ll describe what I do and what i want:

When i click on my actor of type AActor_cu_outline I spawn an actor of type AOutlineEffect in the exact same location,rotation and mesh but with a different material so i can artificially create an outline effect.

Now i want when i click on a different random actor in the scene to destroy this AOutlineEffect. Can you guys help me?I’m stuck on this from yesterday and i just can’t figure out how to do this.

I’ll attach my code here.

void AActor_cu_outline::Creaza_Outline(UPrimitiveComponent* touchedComponent, FKey buttonPressed)

	if (!are_outline)
		FActorSpawnParameters SpawnInfo;

		new_actor = GetWorld()->SpawnActor<AOutlineEffect>(GetActorLocation(), GetActorRotation(), SpawnInfo);



void AOutlineEffect::GetMesh(AActor_cu_outline* Actor)
	this->mesh->SetMaterial(0, Actor->material);
	mesh->SetScalarParameterValueOnMaterials(TEXT("Scale"),Actor->scale );
	mesh->SetVectorParameterValueOnMaterials(TEXT("Color"),Actor->Color );


spontaneous I would suggest storing a reference to your actor (that gets the outline) somewhere where it is accessible from everywhere (like GameMode or GameInstance). If you click a new actor you check if it is the same or a different. If it is a different you destroy your outline. I guess the best approach is anyway to not always spawn and destroy your outline actor. Just disable it and if you want to display it, enable it and place it on the right location.

Hope I understood you problem and my answer will help you.


Hello, yes you understood my problem but I want to know if you can help me, how can i get my GameMode from the actor, is it a function or something?

And if you have the world, you can get the game mode.