Hello,
I have been having an odd issue with UE4 crashing my project and then refusing to open it unless I comment out a few lines of code in a cpp file. (Note, the compile succeeds whether these lines are commented out or not and the game runs as expected if these lines are commented out). I also tried setting the two pointers to nullptr first and then going into these lines of code and the outcome was not changed.
//create and attach the arrow component (will show direction projectile is facing)
pFacing = CreateDefaultSubobject<UArrowComponent>(TEXT("Projectile"));
pFacing->SetupAttachment();
//create and attach the sprite component (visuals for the projectile)
pSprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Projectile"));
pSprite->SetupAttachment(pFacing);
pFacing and pSprite are both in the .h file (I have tried them in both public and protected with allowed private access).
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "pointers", meta = (AllowPrivateAccess = "true"))
UArrowComponent * pFacing;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "pointers", meta = (AllowPrivateAccess = "true"))
class UPaperSpriteComponent * pSprite;
.h includes
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"
.cpp includes
#include "Fishy.h"
#include "Projectile.h"
#include "PaperSpriteComponent.h"
#include "PlayerFish.h"
This takes place in the constructor of the class which is below :
AProjectile::AProjectile()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
if (!)
{
= CreateDefaultSubobject<USceneComponent>(TEXT("Projectile"));
}
// set the variables
MoveSpeed = 500.0f;
MoveMultiplier = 1.0f;
MaxDistance = 350.0f;
CurDistance = 0.0f;
////create and attach the arrow component (will show direction projectile is facing)
//pFacing = CreateDefaultSubobject<UArrowComponent>(TEXT("Projectile"));
//pFacing->SetupAttachment();
////create and attach the sprite component (visuals for the projectile)
//pSprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Projectile"));
//pSprite->SetupAttachment(pFacing);
//pSprite->OnComponentBeginOverlap.AddDynamic(this, &AProjectile::OnOverlapBegin);
//pSprite->bGenerateOverlapEvents = true;
}
The thing that confuses me is that this is basically from an UE4 dev stream (tanks vs zombies) and I have those lines of code (ArrowComp and Sprites) in other classes in my project and they work. The project compiles without errors. I am not sure what about this UE4 does not like but removing that code block allows my game to launch and adding it back in and building the project causes it to close with the ue4 crash error.
I may not be able to check this immediately but any help would be appreciated!