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"

Trying to spawn actors from C++, keep getting error MSB3070, exited with code -1

Hello, I am currently trying to learn how to spawn actors in C++. I took a brief look in how they did it in First Person Template and coded my function like so:

 void AHeroShip::SpawnShield()
 {
     if (Energy >= 50 && ShieldClass != NULL)
     {
 
         const FRotator SpawnRotation = GetControlRotation();
         const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(ShieldOffset);
 
         UWorld* const World = GetWorld();
         if (World != NULL)
         {
             Energy -= 50.f;
             World->SpawnActor<Shield>(ShieldClass, SpawnLocation, SpawnRotation);
         }
     }
 }

Which then I know I'm supposed to say what the class is in blueprint, but I keep getting the error (MSB3070, exited with code -1) Normally, I'm good at finding these bugs and fixing them, but I can't find out what is wrong with the code, any ideas why this might be happening? Any help would be appreciated.

Here is the .h file, I'll also will link the .cpp file if anyone needs to see it.:

 #pragma once
 
 #include "BaseShip.h"
 #include "HeroShip.generated.h"
 
 /**
  * 
  */
 UCLASS(Blueprintable)
 class TWINSTICKEXAMPLE_API AHeroShip : public ABaseShip
 {
     GENERATED_BODY()
 
 public:
     
     AHeroShip();
 
     //Ammo Types
     float BounceShotAmmo;
     float SpreadShotAmmo;
     float BeamShotAmmo;
     
     bool isLow;
 
     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "GunType")
         int32 Type;
 
     UPROPERTY(EditDefaultsOnly, Category = "Shield")
         TSubclassOf<class Shield> ShieldClass;
 
     //Any offsets
     FVector UDOffset;
     FVector ShieldOffset;
 
     FTimerHandle EnergyDepleteBoost;
     FTimerHandle RestoreEnergyTimer;
 
 protected:
     
     //movement
     void MoveForward(float Delta);
     void MoveRight(float Delta);
     void MoveUD(); //Move either up or down
     void Boost();
     void notBoost();
 
     //EnergyBased Spawns
     void SpawnShield();
 
     //Gun
     void SetToAuto();
     void SetToBounce();
     void SetToSpread();
     void SetToBeam();
 
     void RestoreEnergy();
 
     virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
     
 };
Product Version: UE 4.9
Tags:
more ▼

asked Nov 07 '15 at 05:09 PM in C++ Programming

avatar image

D3ATH95
41 9 12 16

avatar image Jerry.Richards Nov 07 '15 at 09:33 PM

I'm sorry but what is Shield? Is it derived from AActor?

For me, I perform the following when spawning actors:

 .h
 TSubclassOf<class AMyPawn>  MyPawn;
 
 .cpp
 AMyPawn* pawn = GetWorld()->SpawnActor<AMyPawn>(MyPawn, spawnLocation, spawnRotation);
 

Btw, I thought UE4 by convention requires classes derived from AActor to start with A, as in AShield. If my understanding is correct you may be able to:

 .h
 TSubclassOf<class AShield> Shield;
 
 .cpp
 World->SpawnActor(Shield, SpawnLocation, SpawnRotation);
 
avatar image D3ATH95 Nov 08 '15 at 05:35 PM

Hello, sorry for the late response. I ended up having to scrap the whole project because the base character wasn't working properly (Errors were everywhere, and I didn't change anything.) But thanks for your help anyhow. :/

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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