x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[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));
Product Version: Not Selected
Tags:
more ▼

asked Dec 05 '14 at 06:22 PM in C++ Programming

avatar image

Jurif
627 26 15 45

avatar image Jurif Dec 14 '14 at 09:00 PM

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: https://forums.unrealengine.com/showthread.php?53230-Unreal-Engine-4-6-Released! https://forums.unrealengine.com/showthread.php?53389-4-6-Transition-Guide

avatar image wettrix Dec 15 '14 at 06:23 AM

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

https://answers.unrealengine.com/questions/146148/cannot-spawn-blueprint-from-c.html

avatar image Jurif Dec 15 '14 at 04:31 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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: https://answers.unrealengine.com/questions/145043/460-cant-get-variables-from-other-blueprint-like-4.html 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!

more ▼

answered Mar 02 '15 at 01:47 PM

avatar image

Jurif
627 26 15 45

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Dec 16 '14 at 07:30 AM

avatar image

Rama
10.6k 446 345 1088

avatar image Jurif Dec 16 '14 at 03:43 PM

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 : alt text 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 : alt text

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.

screenshot317.jpg (28.9 kB)
screenshot318.jpg (36.8 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question