Disable an Actor

So I elected to implement an empty class and called it HelperClass, so I can just access its static functions. The following are the methods I used, you can always extend this to disable other things you want to as well:

void HelperClass::deactivateActor(AActor* actor)
{
	// Deactivate this actor
	actor->SetActorHiddenInGame(true);
	actor->SetActorEnableCollision(false);
	actor->SetActorTickEnabled(false);

	// Call on children
	TArray<AActor*> children;
	actor->GetAllChildActors(children);			// Actual children
	actor->GetAttachedActors(children, false);	// Attached actors. Don't reset array
	for (auto child : children)
		deactivateActor(child);

}

void HelperClass::activateActor(AActor* actor)
{
	// Activate this actor
	actor->SetActorHiddenInGame(false);
	actor->SetActorEnableCollision(true);
	actor->SetActorTickEnabled(true);

	// Call on children
	TArray<AActor*> children;
	actor->GetAllChildActors(children);			// Actual children
	actor->GetAttachedActors(children, false);	// Attached Actors. Don't reset array
	for (auto child : children)
		activateActor(child);
}
1 Like