I don’t understand why my actor doesn’t spawn…
Code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "PacManNode.h"
// Sets default values
APacManNode::APacManNode()
{
// 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;
// Create a static mesh component
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
// Set the static mesh component as the root component
RootComponent = StaticMeshComponent;
}
// Called when the game starts or when spawned
void APacManNode::BeginPlay()
{
Super::BeginPlay();
//Spawn a node
APacManNode* Node = GetWorld()->SpawnActor<APacManNode>(NodeClass, GetActorLocation(), GetActorRotation());
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PacManNode.generated.h"
UCLASS()
class PACMAN_API APacManNode : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APacManNode();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// EditAnywhere: Indicates that this property can be edited by property windows
UPROPERTY(EditAnywhere)
UStaticMeshComponent* StaticMeshComponent;
UPROPERTY(EditAnywhere)
TSubclassOf<APacManNode> NodeClass;
};