I am trying to set a variable inside a component whenever an actor with that component is placed in a world in the editor. The use case for this is to create a GUID for the component when it is placed in the editor. How can something like this be accomplished? Thanks.
I ended up writing an editor module that assigns a GUID when a new actor is dragged into the scene like this:
void FEditorModule::StartupModule()
{
ActorDragged = FEditorDelegates::OnNewActorsDropped.AddRaw(this, &FEditorModule::OnActorDragged);
}
void FEditorModule::ShutdownModule()
{
FEditorDelegates::OnNewActorsDropped.Remove(ActorDragged);
}
void FEditorModule::OnActorDragged(const TArray <UObject*>& Objects, const TArray<AActor*>& Actors)
{
// assign a GUID to the guid component of any actor dragged into the world
for (AActor* Actor : Actors)
{
UGuidComponent* GuidComponent = Cast<UGuidComponent>(Actor->GetComponentByClass(UGuidComponent::StaticClass()));
if (GuidComponent)
{
GuidComponent->SetupComponent();
}
}
}