TActorIterator: how to cast?

In my Level BP, I’ve got some nodes that can find all Spotlights and print out their parameters - see below. My question is: how do I achieve this in code? So far I’ve got:

for (TActorIterator<ALight> Iter(GEditor->LevelViewportClients[0]->GetWorld()); Iter; ++Iter)
	FLightInScene *TheLight = new FLightInScene;
	TheLight->Translation[0] = Iter->GetActorLocation().X;
	TheLight->Translation[1] = Iter->GetActorLocation().Y;
	TheLight->Translation[2] = Iter->GetActorLocation().Z;

	if (Iter->GetClass()->GetDesc().Equals(TEXT("SpotLight")))
		TheLight->LightType = ELightTypes::SpotLight;
		StaticCastSharedPtr<ASpotLight> ????


How do I cast to a spotlight so I can get the spotlight-specific parameters?


Hey -

You should be able to use an Unreal cast.

AActorSubclass* SubActor = Cast<AActorSubclass>(ActorToCast);
//Some Code

This syntax says to take ActorToCast, which may be an AActor or another class by default, and cast it to AActorSubclass. Then, if that cast succeeds (ActorToCast is a member of AActorSubclass) then you can preform the necessary code.


Thanks ! That works perfectly.