Particle System Component null pointer. (4.16.3)

Hey, i’ve been struggling with this for a while now, i hope someone can help me see the problem.

So i’m just adding two UParticleSystemComponent to my Projectile class (based on AActor), one is named “LaunchBlast” and the other one “ImpactBlast”

The problem is LaunchBlast its taking a null pointer as seen here in the details tab, which is empty and obviously i can’t set its template to the desired particle effect.
But ImpactBlast works just fine, as seen here , weird.

Here is how i’m declaring those pointers:

Projectile.h:



#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"

class UProjectileMovementComponent;
class UStaticMeshComponent;
class UParticleSystemComponent;

UCLASS()
class TANKGAME_API AProjectile : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AProjectile();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	

	void LaunchProjectile(float Speed);

private:

	UProjectileMovementComponent * ProjectileMovementComponent = nullptr;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	UStaticMeshComponent* CollisionMesh = nullptr;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	UParticleSystemComponent* LaunchBlast = nullptr;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	UParticleSystemComponent* ImpactBlast = nullptr;
	
};


Projectile.cpp:



#include "Projectile.h"

//IWYU
#include "GameFramework/ProjectileMovementComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include "Components/StaticMeshComponent.h"


// Sets default values
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 = false;

	ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>("Projectile Movement Component");
	ProjectileMovementComponent->bAutoActivate = false;

	CollisionMesh = CreateDefaultSubobject<UStaticMeshComponent>("Collision Mesh Component");
	SetRootComponent(CollisionMesh);
	CollisionMesh->SetNotifyRigidBodyCollision(true);


	LaunchBlast = CreateDefaultSubobject<UParticleSystemComponent>("Launch Blast Component");
	LaunchBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); 

	ImpactBlast = CreateDefaultSubobject<UParticleSystemComponent>("Impact Blast Component");
	ImpactBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
	ImpactBlast->bAutoActivate = false;

}

// Called when the game starts or when spawned
void AProjectile::BeginPlay()
{
	Super::BeginPlay();
	
}

void AProjectile::LaunchProjectile(float Speed)
{
	ProjectileMovementComponent->SetVelocityInLocalSpace(FVector::ForwardVector * Speed);
	ProjectileMovementComponent->Activate();
}


I know it’s a null pointer because i made a OnHit() event for the Projectile and made it so that the LaunchBlast deactivates OnHit(), and it crashes.

Instead of:



	LaunchBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); 


Try:



	LaunchBlast->SetupAttachment(RootComponent); 


I don’t know if that is actually the problem but I have never used AttachToComponent in the constructor.

Thanks, i’ll give it a try anyway SetupAttachment looks a lot nicer than AttachToComponent

Sorry to resurrect an old post, but did you manage to solve this Problem? I’m currently on 4.21.2 and have the exact same problem.

I have a c++ actor-class which holds 3 Particle System Components but only one is accessible. They are created in the constructor and shown in the derived blueprint but shortly afterwards they are NULL and inaccessible in the derived Blueprint.

If I create a blueprint actor with 3 Particle System Components it works just fine.

Edit: I just deleted the derived blueprint and created it once more. Everything works fine now. Unreal Engine Magic I guess…

Refer to the bug report of this problem. The issue can be fixed by renaming the component (the variable, not the component’s name itself) + build and restart the engine.