mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
fix bug with root attachment
"as natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily"
This commit is contained in:
@@ -6,7 +6,7 @@ DEFINE_LOG_CATEGORY(SpawnableActorLog);
|
||||
|
||||
ASpawnableActor::ASpawnableActor()
|
||||
{
|
||||
UE_LOG(EventSourceLog, Log, TEXT("CTOR()"));
|
||||
UE_LOG(SpawnableActorLog, Log, TEXT("CTOR()"));
|
||||
|
||||
// Set this actor to call Tick() every frame.
|
||||
// You can turn this off to improve performance if you don't need it.
|
||||
|
||||
@@ -8,11 +8,14 @@ DEFINE_LOG_CATEGORY(SpawnableSkeletalMeshActorLog);
|
||||
|
||||
ASpawnableSkeletalMeshActor::ASpawnableSkeletalMeshActor()
|
||||
{
|
||||
UE_LOG(SpawnableSkeletalMeshActorLog, Log, TEXT("CTORz"));
|
||||
|
||||
// Set this actor to call Tick() every frame.
|
||||
// You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
BaseMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("BaseMesh"));
|
||||
RootComponent = BaseMeshComponent;
|
||||
BaseMeshComponent->SetupAttachment(RootComponent);
|
||||
}
|
||||
|
||||
@@ -22,8 +25,32 @@ ASpawnableSkeletalMeshActor::~ASpawnableSkeletalMeshActor() {
|
||||
void ASpawnableSkeletalMeshActor::SetSpawnableSkeletalMesh(USkeletalMesh* skeletalMesh)
|
||||
{
|
||||
BaseMesh = skeletalMesh;
|
||||
|
||||
BaseMeshComponent->SetSkeletalMesh(BaseMesh);
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
BaseMeshComponent->SetAllBodiesCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
|
||||
|
||||
BaseMeshComponent->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
|
||||
BaseMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||
BaseMeshComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
|
||||
|
||||
//BaseMeshComponent->SetAllBodiesCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
|
||||
|
||||
//BaseMeshComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Block);
|
||||
//BaseMeshComponent->SetUseCCD(true);
|
||||
//BaseMeshComponent->SetEnableGravity(true);
|
||||
//BaseMeshComponent->SetSimulatePhysics(true);
|
||||
|
||||
//SetActorEnableCollision(true);
|
||||
|
||||
//BaseMeshComponent->SetCollisionProfileName("Custom...", true);
|
||||
|
||||
//BaseMeshComponent->SetCollisionObjectType(ECollisionChannel::ECC_Pawn);
|
||||
//BaseMeshComponent->SetAllBodiesCollisionObjectType(ECollisionChannel::ECC_Pawn);
|
||||
|
||||
//BaseMeshComponent->SetCollisionResponseToAllChannels(ECR_Block);
|
||||
//BaseMeshComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block);
|
||||
|
||||
//BaseMeshComponent->SetAllBodiesSimulatePhysics(true);
|
||||
//BaseMeshComponent->UpdateCollisionProfile();
|
||||
//BaseMeshComponent->UpdatePhysicsToRBChannels();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ ASpawnableActor* ASpawningActor::Spawn()
|
||||
|
||||
// We don't want to keep the actor around indefinitely since they may pile up unused.
|
||||
// Optionally, we could maintain a queue and cull the oldest actors.
|
||||
spawnedActor->StartDestroyTimer(10.0);
|
||||
spawnedActor->StartDestroyTimer(100.0);
|
||||
|
||||
return spawnedActor;
|
||||
}
|
||||
@@ -108,21 +108,24 @@ ASpawnableStaticMeshActor* ASpawningActor::SpawnStaticMeshActor()
|
||||
|
||||
// We don't want to keep the actor around indefinitely since they may pile up unused.
|
||||
// Optionally, we could maintain a queue and cull the oldest actors.
|
||||
spawnedActor->StartDestroyTimer(10.0);
|
||||
spawnedActor->StartDestroyTimer(100.0);
|
||||
|
||||
return spawnedActor;
|
||||
}
|
||||
|
||||
ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor()
|
||||
{
|
||||
FActorSpawnParameters actorSpawnParams;
|
||||
actorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
|
||||
// Spawn actor
|
||||
// TODO(bt): This will memory leak.
|
||||
ASpawnableSkeletalMeshActor* spawnedActor = (ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(ASpawnableSkeletalMeshActor::StaticClass());
|
||||
//ASpawnableSkeletalMeshActor* spawnedActor =
|
||||
// (ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(ASpawnableSkeletalMeshActor::StaticClass());
|
||||
|
||||
// Get player location
|
||||
FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
|
||||
|
||||
|
||||
// Teleport actor randomly
|
||||
// TODO(bt): Put this in front of the camera, or on the (camera -> player) arc!
|
||||
float x = FMath::RandRange(-4000.0f, 4000.0f);
|
||||
@@ -136,17 +139,25 @@ ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor()
|
||||
);
|
||||
|
||||
FRotator rotation;
|
||||
spawnedActor->SetActorLocationAndRotation(
|
||||
/*spawnedActor->SetActorLocationAndRotation(
|
||||
location,
|
||||
rotation,
|
||||
false,
|
||||
0,
|
||||
ETeleportType::ResetPhysics
|
||||
);*/
|
||||
|
||||
ASpawnableSkeletalMeshActor* spawnedActor =
|
||||
(ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(
|
||||
ASpawnableSkeletalMeshActor::StaticClass(),
|
||||
&location,
|
||||
&rotation,
|
||||
actorSpawnParams
|
||||
);
|
||||
|
||||
// We don't want to keep the actor around indefinitely since they may pile up unused.
|
||||
// Optionally, we could maintain a queue and cull the oldest actors.
|
||||
spawnedActor->StartDestroyTimer(10.0);
|
||||
spawnedActor->StartDestroyTimer(100.0);
|
||||
|
||||
return spawnedActor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user