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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Spawning blueprint actor from C++ fails

I made a projectile class, which is basically for now the same thing as the projectile in the twin stick shooter demo project. I then made a blueprint that derived from it. I'd like to be able to spawn this blueprint but every time I try to do a SpawnActor it returns NULL. In the header of the file I'm trying to do this in, I have declared:

class UBlueprint* HeavyProjectileActor;

In the constructor for it, I have:

 struct FConstructorStatics
 {
     ConstructorHelpers::FObjectFinder<UBlueprint> HeavyProjectileRef;
 
     FConstructorStatics() :
         HeavyProjectileRef(TEXT("Blueprint'/Game/Blueprints/B_Heavy_Projectile.B_Heavy_Projectile'"))
     {
     }
 };
 static FConstructorStatics ConstructorStatics;
 
 HeavyProjectileActor = ConstructorStatics.HeavyProjectileRef.Object;

And in the part where I'm trying to spawn the actor I do this:

 AActor* a = World->SpawnActor(HeavyProjectileActor->GetClass(), &SpawnLocation, &FireRotation);

(SpawnLocation and FireRotation are set up above it). The projectile is never added and the return result from SpawnActor is NULL.

My guess is I screwed up how I'm trying to get the blueprint reference. Please note that when I break at that line and view the contents of HeavyProjectileActor it's not NULL and appears to be populated with valid data.

Product Version: Not Selected
Tags:
more ▼

asked Jan 23 '15 at 10:06 AM in C++ Programming

avatar image

Architekt
66 13 16 22

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

1 answer: sort voted first

OK after some sleep I figured it out. For one, I needed to declare the variable as a UClass* not a UBlueprint*. I then changed line 12 in the previous code block I pasted to:

 HeavyProjectileActor = ConstructorStatics.HeavyProjectileRef.Object->GeneratedClass;

Note that it's just appending ->GeneratedClass to what used to be there.

Then for spawning, I just simply pass in HeavyProjectileActor rather than HeavyProjectileActor->GetClass().

more ▼

answered Jan 23 '15 at 07:42 PM

avatar image

Architekt
66 13 16 22

(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