The Enemy don't spawn on the world

Unreal is compiling the code but the enemy don’t spawn on the map. I made a blueprint for EnemyController and a blueprint for FPSShooterGameMode, i used the BP_Enemy for spawning enemies in BP_FPSShooterGameMode, I also selected for GameMode Override in World Settings the BP_FPSShooterGameMode but nothing happens, here is my code:

EnemyController.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Components/BoxComponent.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnemyController.generated.h"

UCLASS()
class FPSSHOOTER_API AEnemyController : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AEnemyController();


	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	// Called every frame
	virtual void Tick(float DeltaSeconds) override;

	
	UPROPERTY(EditAnywhere)
		UShapeComponent* RootBox;

	UPROPERTY(EditAnywhere)
		float Speed = 200.0f;

	FVector Direction;

	UFUNCTION()
		void OnOverlap(UPrimitiveComponent* OverlappedCommponent, AActor* OtherActor,
			UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep,
			const FHitResult& SweepResult);

};

EnemyController.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "EnemyController.h"
#include "Kismet/GameplayStatics.h"
#include "FPSShooterGameMode.h"


// Sets default values
AEnemyController::AEnemyController()
{
 	// 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;

	RootBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Root"));
	RootBox->bGenerateOverlapEvents = true;
	RootBox->OnComponentBeginOverlap.AddDynamic(this, &AEnemyController::OnOverlap);
	
	RootComponent = RootBox;
}

// Called when the game starts or when spawned
void AEnemyController::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AEnemyController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AEnemyController::OnOverlap(UPrimitiveComponent* OverlappedCommponent, AActor* OtherActor,
	UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep,
	const FHitResult& SweepResult)
{
	if (OtherActor == GetWorld()->GetFirstPlayerController()->GetPawn())
	{
		UGameplayStatics::SetGamePaused(GetWorld(), true);
	}
}

FPSShooterGameMode.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "FPSShooterGameMode.generated.h"

/**
 * 
 */
UCLASS()
class FPSSHOOTER_API AFPSShooterGameMode : public AGameModeBase
{
	GENERATED_BODY()

	float MINIMUM_INTERVAL = 0.5f;
	float MAXIMUM_INTERVAL = 2.0f;
	float TIME_TO_MINIMUM_INTERVAL = 30.0f;
	
public:

	virtual void BeginPlay() override;

	virtual void Tick(float DeltaSeconds) override;

	void IncrementScore();
	void OnGameOver();
	void OnRestart();

	UPROPERTY(EditAnywhere, Category = "Spawning")
		TSubclassOf<class AEnemyController> EnemyBlueprint;

	float EnemyTimer;
	float GameTimer;

protected:

	int Score = 0;

	
};

FPSShooterGameMode.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "FPSShooterGameMode.h"
#include "EnemyController.h"
#include "FPSShooter.h"

void AFPSShooterGameMode::BeginPlay()
{
	Super::BeginPlay();
}

void AFPSShooterGameMode::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	GameTimer += DeltaTime;
	EnemyTimer -= DeltaTime;

	if (EnemyTimer <= 0.0f)
	{
		float difficultyPercentage = FMath::Min(GameTimer / TIME_TO_MINIMUM_INTERVAL, 1.0f);

		EnemyTimer = MAXIMUM_INTERVAL - (MAXIMUM_INTERVAL - MINIMUM_INTERVAL) * difficultyPercentage;

		UWorld* World = GetWorld();

		if (World)
		{
			float distance = 800.0f;
			float randomAngle = FMath::RandRange(0.0f, 360.0f);

			FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();

			FVector enemyLocation = playerLocation;

			enemyLocation.X += FMath::Cos(randomAngle * 3.14f / 180.0f) * distance;
			enemyLocation.Y += FMath::Sin(randomAngle * 3.14f / 180.0f) * distance;
			enemyLocation.Z = 210.0f;

			AEnemyController* enemy = World->SpawnActor<AEnemyController>(
				EnemyBlueprint, enemyLocation, FRotator::ZeroRotator);
		}
	}

}

void AFPSShooterGameMode::IncrementScore()
{

}


void AFPSShooterGameMode::OnGameOver()
{

}

void AFPSShooterGameMode::OnRestart()
{

}

Hey there,

Put a breakpoint on the SpawnActor call and see what is the value of the enemy variable, assuming it’s null then what might be happening is that the position you’ve set might prevent (if it’s colliding with the floor or other objects) the character from spawning, you have to change the spawn collision settings to be spawn always and see if that solves it.

Just as a side note: Using Controller in the name of an object that doesn’t derive from the AController hierarchy is a bit missleading.

Check the output log. You may see a warning there, telling why it is not spawned.

I kinda new to VS i don’t know what settings to use for break-point

Just put the cursor in the line and hit F9 a red ball should appear on the left side. To remove it just hit F9 again.

That i didt, what do i press after the red ball is there?

In the World Outliner there is no Enemy Spawing!

Add a random line after the SpawnActor like int32 test = 32; and put the breakpoint in that line instead of the SpawnActor. Once you have that, run the workflow in your game that triggers that code and the execution will halt once you’ve reached the breakpoint (you’ll see a yellow arrow where the red ball is). From there you can hover your mouse on enemy varible and it should tell you the result. Probably it will be nullptr.

Confirm it with the breakpoint, if it’s nullptr then what you need to do is go to the blueprint of the actor you are spawn and go into it’s default options and search for Spawn collision or something like that, there should be an option to spawn always, see if that fixes it.

This is what happening

You need to hit Compile button (next to Play Button) to update the build.

I did that Compile Completed! was written in the bottom right corner of the Unreal Engine

PS:

224272-capture3.png

Did the breakpoint color changed to red? If not then restart the engine from visual studio. What you want is to have the breakpoint red while running the engine. But before you do that, try what i suggested, go to the blueprint of the actor you are spawning and search for Spawn Collision Handling Method and set it to AlwaysSpawn and see if that fixes the problem.

If im using debug the visual is starting the project, i cant make the VS to stop at the break point i dont know how to do that
currently watching youtube videos on how to use breakpoints… no idea still what are u asking for me…but i got these 3 errors looks like->

Try what i suggested before checking the breakpoint. Did it spawn?

Nope! Nothing!

Those errors aren’t really important.

Did you set EnemyBlueprint to the blueprint you sent the screenshot on the class defaults? If you did then we need to check the breakpoint and see what values are being set on the SpawnActor function call.

The BP_Enemy is set to BP_FPSShooter, dont know what supposed to happen with that break point cause doesnt show me anything
And again i dont know what pic off VS to show u, that break point is always red

Do you have the red breakpoint? If not just do this after the SpawnActor:

if(EnemyBlueprint == nullptr)
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("NULL Enemy Blueprint!"));

if(enemy == nullptr)
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("NULL Enemy Instance!"));