Spawning Actors via Player Controller UE4Editor.exe Break Trigger

  • Using TopDownCode Template
  • Followed UE4Programming Tutorial on YouTube for Battery Pickup with a bit of a change
  • Created “Ship” class which extends AActor
  • Created “CarrierShip” class which extends AShip
  • TopDownPlayerController.cpp contains: “InputComponent->BindAction(“SpawnUnitAtLocation”, IE_Pressed, this, &ATopDownPlayerController::SelectedSpawnLocation);”

The “Selected Spawn Location” function is as follows:

void ATopDownPlayerController::SelectedSpawnLocation(){
	FHitResult Hit;
	GetHitResultUnderCursor(ECC_Visibility, false, Hit);
	FVector Location = Hit.ImpactPoint;
	FString LocationString = "Left Clicked At: " + Location.ToString();
	SendMessageToScreenByString(LocationString, 2.f);
	FActorSpawnParameters params;
	params.Name = TEXT("Ship");
	FRotator Rotation = FRotator(0.f, 0.f, 0.f);
	UWorld* World = GetWorld();
	//ACarrierShip* Ship;
	if (World){
		World->SpawnActor<ACarrierShip>(ACarrierShip::StaticClass(), Location, Rotation, params);
	}

and the .h for TopDownPlayerController defines in “protected” as “void SelectedSpawnLocation();”

Ship.cpp >

#include "TopDown.h"
#include "Ship.h"



AShip::AShip(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComponent"));
	RootComponent = BaseCollisionComponent;
	ShipMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("ShipMesh"));
	ShipMesh->SetSimulatePhysics(true);
	ShipMesh->AttachTo(RootComponent);
}
void AShip::OnSpawned_Implementation(){

}

Ship.h >

#pragma once

#include "GameFramework/Actor.h"
#include "Ship.generated.h"

/**
 *
 */
UCLASS()
class TOPDOWN_API AShip : public AActor
{
	GENERATED_BODY()
public:
	AShip(const FObjectInitializer& ObjectInitializer);
	UFUNCTION(BlueprintNativeEvent)
	void OnSpawned();
protected:
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Ship)
		USphereComponent* BaseCollisionComponent;
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Ship)
		UStaticMeshComponent* ShipMesh;



};

CarrierShip.cpp >

#include "TopDown.h"
#include "CarrierShip.h"


ACarrierShip::ACarrierShip(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

}
void ACarrierShip::OnSpawned_Implementation(){
	Super::OnSpawned_Implementation();
}

CarrierShip.h >

#pragma once

#include "Ship.h"
#include "CarrierShip.generated.h"

/**
 *
 */
UCLASS()
class TOPDOWN_API ACarrierShip : public AShip
{
	GENERATED_BODY()
public:
	ACarrierShip(const FObjectInitializer& ObjectInitializer);
	void OnSpawned_Implementation() override;

};

Question:

During first successful click, actor is spawned at location and named as needed. During second successful click, new actor is not spawned, instead I get a VS2013 Error showing "UE4Editor.exe Has Triggered A Breakpoint" with no extra details. Anyone know what I'm doing wrong... Sorry, new at this.