I have some code that requires stuff on the actor for it to work, and I’m moving all of the functionality into an ActorComponent to avoid hardcoding a dependency on specific actors for this subsystem. I have an implementation that works, but spawns the ActorComponent at the wrong location.
FORCEINLINE void setupSCComponentWithCollision(USphereComponent *comp)
{
if(!comp)
return;
comp->bOwnerNoSee = false;
comp->bCastDynamicShadow = false;
comp->CastShadow = false;
comp->BodyInstance.SetObjectType(ECC_WorldDynamic);
comp->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryOnly);
comp->BodyInstance.SetResponseToAllChannels(ECR_Ignore);
comp->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Ignore);
comp->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Ignore);
comp->BodyInstance.SetResponseToChannel(ECC_Pawn, ECR_Overlap);
comp->SetHiddenInGame(false);
comp->SetSphereRadius(179.641708f);
}
Current implementation on UActorComponent derived class:
void UBaseDialogue::InitializeComponent()
{
Super::InitializeComponent();
dialogueCollision = NewObject<USphereComponent>(GetOwner(), USphereComponent::StaticClass());
setupSCComponentWithCollision(dialogueCollision);
GetOwner()->AttachToComponent(dialogueCollision, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
GetOwner()->FinishAndRegisterComponent(dialogueCollision);
}
Former implementation on AActor derived class:
ADialogueActor::ADialogueActor()
{
PrimaryActorTick.bCanEverTick = true;
dialogueCollision = CreateDefaultSubobject<USphereComponent>(TEXT("DialogueCollision"));
SetupSCComponentWithCollision(dialogueCollision);
}
Nothing shows up in the editor hierarchy at runtime. How can I set this up to properly create the USphereComponent on the actor at runtime and show it in that actor’s hierarchy? How Can I set this up to create the USphereComponent on the actor at the moment of attachment, while still editing?