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.