[Resolved]SpawnActor failed ? Spawning a Blueprint

Hi, I am returning to UE4 after some time and ran into an issue with updating my project to 4.6 version.
The latest tested and working version for my project was 4.5.1.
Now I tried this 2 ways, first I just opened the project in 4.6 and it automatically compiles it to 4.6 version,
then I also tried recreating the whole project from start.
I ended up with same problem, I can’t seem to spawn blueprints, the log says:

" SpawnActor failed because no class was specified "!

The rest of the game works fine.
I assume the problem is something about ObjectInitializer which seems to have changed from
FPostConstructInitializeProperties& PCIP way of doing it ?? I tried it both ways, no luck so far.

Here’s the code , .h:

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/GameMode.h"
#include "JumpyFrogsGameMode.generated.h"

/** GameMode class to specify pawn and playercontroller */
UCLASS(minimalapi)
class AJumpyFrogsGameMode : public AGameMode
{
	GENERATED_BODY()

public:
	AJumpyFrogsGameMode(const FObjectInitializer& ObjectInitializer);

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = JumpyFrogs)
		UClass* SlotBP;
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = JumpyFrogs)
		UClass* FrogBP;
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = JumpyFrogs)
		AActor* MeshHolder; 

// and so on…
.cpp:

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

#include "JumpyFrogs.h"
#include "JumpyFrogsGameMode.h"
#include "JumpyFrogsPlayerController.h"

#include "ConstructorHelpers.h"
#include "JumpyFrogCharacter.h"
#include "Engine.h"

AJumpyFrogsGameMode::AJumpyFrogsGameMode(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// no pawn by default
	DefaultPawnClass = NULL;
	// use our own player controller class
	PlayerControllerClass = AJumpyFrogsPlayerController::StaticClass();
	bIsFrogSelected = false;
	bIsMoveValid = false;
	bIsFrogInAction = false;
	
	static ConstructorHelpers::FObjectFinder <UBlueprint> FrogOb(TEXT("Blueprint'/Game/FrogChar/Blueprints/FrogBP.FrogBP'"));
	if (FrogOb.Object != NULL)
	{
		FrogBP = (UClass*)FrogOb.Object->GeneratedClass;
	}
	static ConstructorHelpers::FObjectFinder <UBlueprint> SlotOb(TEXT("Blueprint'/Game/Blueprints/EmptySlotBP.EmptySlotBP'"));
	if (SlotOb.Object != NULL)
	{
		SlotBP = (UClass*)SlotOb.Object->GeneratedClass;
	}

}

and so on… and the spawning part:

TheSlotsArray.Add(GetWorld()->SpawnActor<AActor>(SlotBP, FVector(0.0f, 440.0f, 60.0f), FRotator(0.0f, 0.0f, 0.0f), SpawnInfo));
FrogsArray.Add(GetWorld()->SpawnActor<AJumpyFrogCharacter>(FrogBP, MojVektor, FRotator(0.0f, 0.0f, 0.0f), SpawnInfo));
FrogsArray.Add(GetWorld()->SpawnActor<AJumpyFrogCharacter>(FrogBP, FVector(0.0f, 220.0f, 60.0f), FRotator(0.0f, 0.0f, 0.0f), SpawnInfo));
FrogsArray.Add(GetWorld()->SpawnActor<AJumpyFrogCharacter>(FrogBP, FVector(0.0f, 660.0f, 60.0f), FRotator(0.0f, 0.0f, 0.0f), SpawnInfo));

I will probably delete this question, I’ll leave it for now to solve the problem first,
the problem is obviously the deprecated constructor changed to FObjectInitializer , so I need to find an example of constructing and spawning a blueprint with new method.
Here is some info from the forums:
Unreal Engine 4.6 Released! - Announcements - Unreal Engine Forums!
4.6 Transition Guide - C++ - Unreal Engine Forums

I did find a solution to this before and posted a exmaple code on the previous answer topic. Hope it helps

Thanks, but doesn’t work for me, I am starting to think its better to wait till 4.7 version.

#BPs Are Set?

Are you sure FrogBP and SlotBP are set properly and that you are using your Blueprint version of your Game Mode?

Rama

Yes I am sure, I even rebuilt the project. Spawn function in GameMode class actually gets called from my GameModeBP,
and everything works except the spawning parts, the HUD too is a BP and works.

Either I do it the old FConstructor way or new FObjectInitializer , if it compiles I either get “SpawnActor failed because no class was specified”,
or the editor crashes on load because of the “Spawn” line.
I tried it many ways, FObjectFinder, FClassFinder, .Class, GetClass, GetBlueprintClass, .object->GeneratedClass; and so on…

So this is what I tried today , I created a new project from TOP DOWN template in C++ , created a AActor Blueprint and tryed to spawn it in the GameMode class:
Test1:

static ConstructorHelpers::FClassFinder<AActor> TestActor(TEXT("/Game/Blueprints/TestActorBP.TestActorBP"));
if (TestActor.Class != NULL)
	{
		UClass* TA = TestActor.Class;
		LilyPadsArray.Add(GetWorld()->SpawnActor<AActor>(TA, FVector(0.0f, 0.0f, 0.0f), FRotator(0.0f, 0.0f, 0.0f)));
	}

and when I run debugger I get this error :

24215-screenshot317.jpg

Test2:

struct FConstructorStatics
	{
		ConstructorHelpers::FObjectFinderOptional<UBlueprint> TestActor2;
		FConstructorStatics()
			: TestActor2(TEXT("Blueprint'/Game/Blueprints/TestActorBP.TestActorBP'"))
		{
		}
	};
	static FConstructorStatics ConstructorStatics;
	// Save a pointer 
	    if (ConstructorStatics.TestActor2.Get() != NULL)
	{
		TA2 = ConstructorStatics.TestActor2.Get()->GetBlueprintClass();
		LilyPadsArray.Add(GetWorld()->SpawnActor<AActor>(TA2, FVector(0.0f, 0.0f, 0.0f), FRotator(0.0f, 0.0f, 0.0f)));
	}

Then when I run debugger I get this error :

24216-screenshot318.jpg

If I move the spawning line to a new function , it compiles and when the function is called in game in the log it says :
“SpawnActor failed because no class was specified”

Any way I try it I get same results.

Well I figured out what the problem was, it has something to do with the new blueprint system, it lost access to variables from parent Class,
similar to problem described here:

In my case the problem is with GameModeBlueprint, simply put if I choose my GameModeBlueprint in the World Settings, I can call all the functions from parent GameMode C++ class, however the function can’t seem to access some the variables. it can access int32 and such variables, but not arrays , pointers to BPs, etc. If I “Force Legacy Menuing system” in the “Blueprint Editor” , the problem stays. So instead of spawning Frogs in the MyGameMode->SpawnFrogsFunction, I created a BlueprintImplementableEvent:

UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "SpawnFrogsFromBP"))
		virtual void SpawnFrogFromBP(FVector FrogCoordinates);

this way I can just do this from the function:
this->SpawnFrogFromBP(FVector(220, 220, 60));

And do the SpawnActor back in the Blueprint, which works great.
It took me way too long to find what was causing this problem, but now it works.
Hopefully this will help others with same problem!