Create Destructible Actor Class

This commit is contained in:
Louis Hobbs 2023-01-16 23:12:35 +00:00
parent fc71693a42
commit 19a5054271
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,35 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Destructable.h"
#include <Kismet/GameplayStatics.h>
// Sets default values
ADestructable::ADestructable()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
this->Tags.Add(FName("Destructable"));
}
// Called when the game starts or when spawned
void ADestructable::BeginPlay()
{
Super::BeginPlay();
if (!this->ActorHasTag(FName("Destructable")))
{
this->Tags.Add(FName("Destructable"));
}
}
void ADestructable::Destruct()
{
// TODO: Add some more logic here
UGameplayStatics::SpawnEmitterAtLocation(this, ParticleEffect, this->ActorToWorld().GetLocation(), FRotator::ZeroRotator, true);
Destroy();
}

View File

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Destructable.generated.h"
UCLASS()
class NAKATOMI_API ADestructable : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
class UParticleSystem* ParticleEffect;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
class UStaticMeshComponent* StaticMesh;
// Sets default values for this actor's properties
ADestructable();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
void Destruct();
};