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"

Spawning Blueprint Objects Problem

Hey guys,

I'm very new to Unreal. I followed the C++ FPS tutorial and have gotten to the end. I figured that in order to get a better understanding of things, I would try to simulate an explosion when the projectile hits something. I came up with the following code, using the already existent Blueprint that comes as an included asset:

 void AFPSProjectile::OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
     if (OtherActor && OtherActor != this && OtherComp)
         OtherComp->AddImpulseAtLocation(ProjectileMovement->Velocity * 100.0f, Hit.ImpactPoint);
         /* now also create explosion on impact*/
         static ConstructorHelpers::FObjectFinder<UBlueprint> explosionBlueprint(TEXT("Blueprint'/Game/Blueprints/Blueprint_Effect_Explosion'"));
         if (explosionBlueprint.Object != NULL)
             UClass* uclass = explosionBlueprint.Object->GeneratedClass;
             FActorSpawnParameters SpawnParameters;
             SpawnParameters.Owner = this;
             SpawnParameters.Instigator = Instigator;
             UWorld* const world = GetWorld();
             if (world)
                 FRotator const rotation = Hit.ImpactNormal.Rotation();
                 AActor* actor = world->SpawnActor<AActor>(uclass, Hit.ImpactPoint, rotation, SpawnParameters);

When I run it, nothing happens when the spheres hit geometry. The impulse does happen as usual, but not the actor spawn. To make things worse, have firing 5 or 6 projectiles, the editor crashes. I'm wondering if I'm doing something incredibly stupid here. Any help would be greatly appreciated!

Product Version: Not Selected
more ▼

asked Apr 09 '14 at 09:52 AM in C++ Programming

avatar image

98 8 10 16

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

1 answer: sort voted first

The line

 static ConstructorHelpers::FObjectFinder<UBlueprint> explosionBlueprint(TEXT("Blueprint'/Game/Blueprints/Blueprint_Effect_Explosion'"));

needs to be in the constructor of the class. You can create a pointer in the header:

 TSubclassOf<class AActor> BallBlueprint;

and then put this into the constructor aswell:

 explosionBP= (UClass*)explosionBlueprint.Object->GeneratedClass;


 AActor* actor = world->SpawnActor<AActor>(explosionBP , Hit.ImpactPoint, rotation, SpawnParameters);

more ▼

answered Apr 09 '14 at 10:33 AM

avatar image

1.9k 53 40 200

avatar image joey.pla Apr 09 '14 at 10:59 AM

Unfortunately my compiler complains: value of type UClass* cannot be assigned to type UBlueprint* . Is it a typo?

avatar image joey.pla Apr 09 '14 at 11:00 AM

Also complains about the SpawnActor function not taking a UBlueprint*

avatar image joey.pla Apr 09 '14 at 11:01 AM

Is it just a matter of casting to UClass* ?

avatar image Dune Apr 09 '14 at 02:36 PM

I made a slight typo, the header should declare the blueprint a subclass of an actor. Updated the code.

(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