mirror of
https://github.com/storytold/ActorSpawningPlugin.git
synced 2026-10-09 00:09:44 +00:00
Spawned sound actors "work" (not tested for segfaults)
This commit is contained in:
@@ -124,7 +124,7 @@ ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor()
|
||||
// (ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(ASpawnableSkeletalMeshActor::StaticClass());
|
||||
|
||||
// Get player location
|
||||
FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
|
||||
FVector playerLocation = LookupPlayerLocation();
|
||||
|
||||
// Teleport actor randomly
|
||||
// TODO(bt): Put this in front of the camera, or on the (camera -> player) arc!
|
||||
@@ -139,13 +139,6 @@ ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor()
|
||||
);
|
||||
|
||||
FRotator rotation;
|
||||
/*spawnedActor->SetActorLocationAndRotation(
|
||||
location,
|
||||
rotation,
|
||||
false,
|
||||
0,
|
||||
ETeleportType::ResetPhysics
|
||||
);*/
|
||||
|
||||
ASpawnableSkeletalMeshActor* spawnedActor =
|
||||
(ASpawnableSkeletalMeshActor*)GetWorld()->SpawnActor(
|
||||
@@ -162,6 +155,38 @@ ASpawnableSkeletalMeshActor* ASpawningActor::SpawnSkeletalMeshActor()
|
||||
return spawnedActor;
|
||||
}
|
||||
|
||||
ASoundSpawnActor* ASpawningActor::SpawnSoundActor(USoundBase* sound)
|
||||
{
|
||||
FVector playerLocation = LookupPlayerLocation();
|
||||
|
||||
// Teleport actor randomly
|
||||
// TODO(bt): Put this in front of the camera, or on the (camera -> player) arc!
|
||||
float x = FMath::RandRange(-1000.0f, 1000.0f);
|
||||
float y = FMath::RandRange(-1000.0f, 1000.0f);
|
||||
float z = FMath::RandRange(1000.0f, 1000.0f);
|
||||
|
||||
FVector location(
|
||||
playerLocation.X + x,
|
||||
playerLocation.Y + y,
|
||||
playerLocation.Z + z
|
||||
);
|
||||
|
||||
FActorSpawnParameters actorSpawnParams;
|
||||
FRotator rotation;
|
||||
|
||||
ASoundSpawnActor* actor =
|
||||
(ASoundSpawnActor*)GetWorld()->SpawnActor(
|
||||
ASoundSpawnActor::StaticClass(),
|
||||
&location,
|
||||
&rotation,
|
||||
actorSpawnParams
|
||||
);
|
||||
|
||||
actor->SetSound(sound);
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
void ASpawningActor::SpawnCallback(FString Channel, FString Message)
|
||||
{
|
||||
UE_LOG(SpawningActorLog, Log, TEXT("SpawnCallback()"));
|
||||
@@ -169,3 +194,8 @@ void ASpawningActor::SpawnCallback(FString Channel, FString Message)
|
||||
Spawn();
|
||||
}
|
||||
|
||||
FVector ASpawningActor::LookupPlayerLocation()
|
||||
{
|
||||
return GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "UObject/NoExportTypes.h"
|
||||
|
||||
// EventCenterPlugin
|
||||
#include "SoundSpawnActor.h"
|
||||
#include "SpawnableActor.h"
|
||||
#include "SpawnableSkeletalMeshActor.h"
|
||||
#include "SpawnableStaticMeshActor.h"
|
||||
@@ -39,6 +40,10 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||
void SpawnCallback(FString Channel, FString Message);
|
||||
|
||||
/** Create sound actor. */
|
||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||
ASoundSpawnActor* SpawnSoundActor(USoundBase* sound);
|
||||
|
||||
/** Mesh to use */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
|
||||
class UStaticMeshComponent* BaseMesh;
|
||||
@@ -49,6 +54,9 @@ protected:
|
||||
|
||||
virtual void BeginDestroy() override;
|
||||
|
||||
// Lookup the player's location.
|
||||
FVector LookupPlayerLocation();
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
Reference in New Issue
Block a user