Launcher crashes at 70% and won't load unless I comment out code

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!

I’m seeing a similar issue when I comment out my calls to SetupAttachment() in UE 4.15

Anyone have any ideas on this issue?

Can you post what you are trying to do? Difficult to see what the issue might be just by mentioning, SetupAttachment( ).

shouldn’t we use different names for subobjects? btw check the return value of CreateDefaultSubobject() by check(pFacing)

I think you have to have different names for the setupattachment

Hello!

This post is a few months old so I wasn’t expecting recent answers! I haven’t touched the project in a while but the odd part was that that exact code snippet worked in other objects (and was from an official UE4 tutorial) but didn’t work in this one object.
The sprite pointer was the only one that wouldn’t work and I worked around this by just adding it manually in the objects blueprint.
I am still not sure why the pSprite * wouldn’t inherit through code in that object but I just took the quicker solution so that I could keep moving.

Thank you to everyone for their responses!