mirror of
https://github.com/storytold/ActorSpawningPlugin.git
synced 2026-10-09 00:09:44 +00:00
Async sound playing works! (in vocodes plugin only)
I haven't spawned this new actor type yet...
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "SoundSpawnActor.h"
|
||||
|
||||
#include "UObject/Object.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(SoundSpawnActorLog);
|
||||
|
||||
ASoundSpawnActor::ASoundSpawnActor()
|
||||
{
|
||||
UE_LOG(SoundSpawnActorLog, Log, TEXT("CTOR()"));
|
||||
}
|
||||
|
||||
ASoundSpawnActor::~ASoundSpawnActor()
|
||||
{
|
||||
}
|
||||
|
||||
void ASoundSpawnActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void ASoundSpawnActor::BeginDestroy()
|
||||
{
|
||||
Super::BeginDestroy();
|
||||
}
|
||||
|
||||
void ASoundSpawnActor::SetSound(USoundBase* sound)
|
||||
{
|
||||
UE_LOG(SoundSpawnActorLog, Log, TEXT("playing sound..."));
|
||||
|
||||
UGameplayStatics::PlaySound2D(
|
||||
this, // world context
|
||||
sound,
|
||||
1.0, // VolumeMultiplier
|
||||
1.0, // PitchMultiplier
|
||||
0.0 // StartTime
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,30 +11,6 @@ ASpawnableActor::ASpawnableActor()
|
||||
// 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;
|
||||
|
||||
/*
|
||||
// Attach a mesh to the object.
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
||||
|
||||
BaseMesh = BaseMeshAsset.Object;
|
||||
|
||||
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||
BaseMeshComponent->SetupAttachment(RootComponent);
|
||||
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
*/
|
||||
|
||||
// NB: Only valid to call in the CTOR.
|
||||
//BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||
//BaseMeshComponent->SetupAttachment(RootComponent);
|
||||
|
||||
// Attach a mesh to the object to try to turn on physics.
|
||||
// Maybe not necessary...
|
||||
//static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));
|
||||
//BaseMeshComponent->SetStaticMesh(BaseMeshAsset.Object);
|
||||
//BaseMeshComponent->SetSimulatePhysics(true);
|
||||
}
|
||||
|
||||
ASpawnableActor::~ASpawnableActor()
|
||||
@@ -56,31 +32,6 @@ void ASpawnableActor::Tick(float DeltaTime)
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
// TODO: This doesn't work outside of constructor
|
||||
/*void ASpawnableActor::SetMeshByString(const FString& meshName)
|
||||
{
|
||||
// Attach a mesh to the object.
|
||||
// eg. TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'")
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> BaseMeshAsset(*meshName);
|
||||
|
||||
BaseMesh = BaseMeshAsset.Object;
|
||||
|
||||
BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
|
||||
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
}*/
|
||||
|
||||
// Works!!
|
||||
/*void ASpawnableActor::SetMesh(UStaticMesh* staticMesh)
|
||||
{
|
||||
BaseMesh = staticMesh;
|
||||
BaseMeshComponent->SetStaticMesh(BaseMesh);
|
||||
BaseMeshComponent->SetSimulatePhysics(true);
|
||||
BaseMeshComponent->UpdateCollisionFromStaticMesh();
|
||||
}*/
|
||||
|
||||
void ASpawnableActor::StartDestroyTimer(float seconds)
|
||||
{
|
||||
GetWorldTimerManager().SetTimer(DestroyTimer, this, &ASpawnableActor::InvokeDestroy, seconds);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
// Unreal Core
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
|
||||
// EventCenterPlugin
|
||||
#include "SoundSpawnActor.generated.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(SoundSpawnActorLog, Log, All);
|
||||
|
||||
UCLASS()
|
||||
class ACTORSPAWNINGPLUGIN_API ASoundSpawnActor : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
ASoundSpawnActor();
|
||||
~ASoundSpawnActor();
|
||||
|
||||
/** Set the sound. */
|
||||
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
|
||||
void SetSound(USoundBase* sound);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void BeginDestroy() override;
|
||||
};
|
||||
|
||||
@@ -21,21 +21,6 @@ public:
|
||||
ASpawnableActor();
|
||||
~ASpawnableActor();
|
||||
|
||||
/** Mesh to use */
|
||||
//UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
|
||||
//class UStaticMeshComponent* BaseMeshComponent;
|
||||
|
||||
/** Mesh to use */
|
||||
//UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
|
||||
//class UStaticMesh* BaseMesh;
|
||||
|
||||
// FIXME: This won't work outside of the ctor :(
|
||||
//UFUNCTION(BlueprintCallable, Category = "SpawnableActor")
|
||||
//void SetMeshByString(const FString& meshName);
|
||||
|
||||
//UFUNCTION(BlueprintCallable, Category = "SpawnableActor")
|
||||
//void SetMesh(UStaticMesh* staticMesh);
|
||||
|
||||
/** Set a timer to destroy this actor. */
|
||||
void StartDestroyTimer(float seconds);
|
||||
|
||||
@@ -55,3 +40,4 @@ public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user