diff --git a/Source/EventCenterPlugin/Private/SpawnableActor.cpp b/Source/EventCenterPlugin/Private/SpawnableActor.cpp index 281d777..ca38bd6 100644 --- a/Source/EventCenterPlugin/Private/SpawnableActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawnableActor.cpp @@ -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. diff --git a/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp b/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp index a766484..08e3c65 100644 --- a/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawnableSkeletalMeshActor.cpp @@ -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(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(); } diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp index 9f4a30f..2ffe4bc 100644 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawningActor.cpp @@ -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; }