Unable to spawn an Actor, Help

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;

};

Hi there @GiacomoPiatelli, welcome to the Unreal Engine forums!

This topic has been moved from International to Programming & Scripting: C++.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

1 Like