Browse Source
+ Follow UE4 example for spawning and destroying actors + https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/SpawnAndDestroyActors/ + This version uses hybrid C++ and Blueprints instead of doing one or the other + Functions to spawn and delete fireballs exposed by UFUNCTION() prefixmaster
19 changed files with 276 additions and 9 deletions
@ -1,7 +1,10 @@
@@ -1,7 +1,10 @@
|
||||
[/Script/EngineSettings.GeneralProjectSettings] |
||||
ProjectID=467E2A14A3B54EB78FE52E4DC9F8CBE4 |
||||
ProjectName=Third Person BP Game Template |
||||
CopyrightNotice=All content (c) Shaun Reed 2021, all rights reserved |
||||
LicensingTerms=MIT |
||||
|
||||
[StartupActions] |
||||
bAddPacks=True |
||||
InsertPack=(PackSource="StarterContent.upack",PackName="StarterContent") |
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
using UnrealBuildTool; |
||||
using System.Collections.Generic; |
||||
|
||||
public class ThirdPersonTarget : TargetRules |
||||
{ |
||||
public ThirdPersonTarget(TargetInfo Target) : base(Target) |
||||
{ |
||||
Type = TargetType.Game; |
||||
DefaultBuildSettings = BuildSettingsVersion.V2; |
||||
|
||||
ExtraModuleNames.AddRange( new string[] { "ThirdPerson" } ); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
|
||||
#include "ActorSpawner.h" |
||||
// Include the header file from the actor we want to spawn
|
||||
#include "BallActor.h" |
||||
|
||||
// Engine includes
|
||||
#include "Components/BoxComponent.h" |
||||
|
||||
// Sets default values
|
||||
AActorSpawner::AActorSpawner() |
||||
{ |
||||
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot")); |
||||
SpawnVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("SpawnVolume")); |
||||
SpawnVolume->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); |
||||
} |
||||
|
||||
void AActorSpawner::SpawnActor() |
||||
{ |
||||
// Get initial position and rotation, then spawn the actor
|
||||
FVector SpawnLocation = GetActorLocation(); |
||||
FRotator SpawnRotation = GetActorRotation(); |
||||
GetWorld()->SpawnActor<ABallActor>(SpawnLocation, SpawnRotation); |
||||
} |
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AActorSpawner::BeginPlay() |
||||
{ |
||||
Super::BeginPlay(); |
||||
|
||||
} |
||||
|
||||
// Called every frame
|
||||
void AActorSpawner::Tick(float DeltaTime) |
||||
{ |
||||
Super::Tick(DeltaTime); |
||||
|
||||
} |
||||
|
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
|
||||
#include "BallActor.h" |
||||
|
||||
|
||||
#include "Components/SphereComponent.h" |
||||
#include "Particles/ParticleSystemComponent.h" |
||||
|
||||
// Sets default values
|
||||
ABallActor::ABallActor() |
||||
{ |
||||
// 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 sphere with the name 'Sphere'
|
||||
SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere")); |
||||
// Attach a static mesh component with the name 'MeshComp'; etc..
|
||||
StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp")); |
||||
ParticleComp = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("ParticleComp")); |
||||
|
||||
// Attach the sphere to the root position of this Actor and configure settings
|
||||
SphereComp->SetupAttachment(RootComponent); |
||||
SphereComp->SetSimulatePhysics(true); |
||||
SphereComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); |
||||
|
||||
// Attach the static mesh to the sphere
|
||||
StaticMeshComp->AttachToComponent(SphereComp, FAttachmentTransformRules::KeepRelativeTransform); |
||||
// Attach the particle system to the static mesh
|
||||
ParticleComp->AttachToComponent(StaticMeshComp, FAttachmentTransformRules::KeepRelativeTransform); |
||||
|
||||
// Set sphere radius to be smaller size in line with the static mesh (?)
|
||||
SphereComp->SetSphereRadius(16.0f * this->sizeScale); |
||||
|
||||
StaticMeshComp->SetRelativeLocation(FVector(0.0f, 0.0f, -12.0f)); |
||||
StaticMeshComp->SetRelativeScale3D(FVector(0.25f, 0.25f, 0.25f)); |
||||
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMesh>SphereMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'")); |
||||
StaticMeshComp->SetStaticMesh(SphereMeshAsset.Object); |
||||
|
||||
static ConstructorHelpers::FObjectFinder<UParticleSystem>ParticleCompAsset(TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Fire.P_Fire'")); |
||||
ParticleComp->SetTemplate(ParticleCompAsset.Object); |
||||
} |
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ABallActor::BeginPlay() |
||||
{ |
||||
Super::BeginPlay(); |
||||
|
||||
|
||||
} |
||||
|
||||
// Called every frame
|
||||
void ABallActor::Tick(float DeltaTime) |
||||
{ |
||||
Super::Tick(DeltaTime); |
||||
|
||||
} |
||||
|
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
#pragma once |
||||
|
||||
#include "CoreMinimal.h" |
||||
#include "GameFramework/Actor.h" |
||||
#include "ActorSpawner.generated.h" |
||||
|
||||
UCLASS(Blueprintable) |
||||
class THIRDPERSON_API AActorSpawner : public AActor |
||||
{ |
||||
GENERATED_BODY() |
||||
|
||||
public: |
||||
// Sets default values for this actor's properties
|
||||
AActorSpawner(); |
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Spawn") |
||||
void SpawnActor(); |
||||
|
||||
protected: |
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override; |
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite) |
||||
class UBoxComponent* SpawnVolume; |
||||
public: |
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override; |
||||
|
||||
}; |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
#pragma once |
||||
|
||||
#include "CoreMinimal.h" |
||||
#include "GameFramework/Actor.h" |
||||
#include "BallActor.generated.h" |
||||
|
||||
UCLASS() |
||||
class THIRDPERSON_API ABallActor : public AActor |
||||
{ |
||||
GENERATED_BODY() |
||||
|
||||
public: |
||||
// Sets default values for this actor's properties
|
||||
ABallActor(); |
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite) |
||||
float sizeScale = 1.0; |
||||
|
||||
protected: |
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override; |
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite) |
||||
class USphereComponent* SphereComp; |
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite) |
||||
UStaticMeshComponent* StaticMeshComp; |
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite) |
||||
class UParticleSystemComponent* ParticleComp; |
||||
|
||||
public: |
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override; |
||||
}; |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
using UnrealBuildTool; |
||||
|
||||
public class ThirdPerson : ModuleRules |
||||
{ |
||||
public ThirdPerson(ReadOnlyTargetRules Target) : base(Target) |
||||
{ |
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; |
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); |
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { }); |
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
} |
||||
} |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
#include "ThirdPerson.h" |
||||
#include "Modules/ModuleManager.h" |
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, ThirdPerson, "ThirdPerson" ); |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
#pragma once |
||||
|
||||
#include "CoreMinimal.h" |
||||
|
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
// All content (c) Shaun Reed 2021, all rights reserved
|
||||
|
||||
using UnrealBuildTool; |
||||
using System.Collections.Generic; |
||||
|
||||
public class ThirdPersonEditorTarget : TargetRules |
||||
{ |
||||
public ThirdPersonEditorTarget(TargetInfo Target) : base(Target) |
||||
{ |
||||
Type = TargetType.Editor; |
||||
DefaultBuildSettings = BuildSettingsVersion.V2; |
||||
|
||||
ExtraModuleNames.AddRange( new string[] { "ThirdPerson" } ); |
||||
} |
||||
} |
Loading…
Reference in new issue