CreateDefaultSubobject with UParticleSystemComponent crashes

Hi everyone!

I have done the steps described in the programming quick start tutorial. Now i want to add a particle system component to my FloatingActor as mentioned in the last step, but the project crashes wehenever i try to create an object of it:

.cpp:
MyParticleSystem = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyParticles"));

.h:
UPROPERTY(EditAnywhere)
UParticleSystemComponent* MyParticleSystem;

What am i doing wrong? Isn’t this the correct way to create an object of UParcticleSystemComponent?

Could you post a complete snippet? Where are you using CreateDefaultSubobject?

Hello ,
i just found the problem, i didn’t call it in the construcotr, instead i called it inside BeginPlay(). In this case one must use the Function NewObject() or NewNamedObject().

Yeah that’s why I asked about where you used it :smiley:

Issue solved. CreateDefaultSubobject must be called in the ctor. Closing issue for tracking purpose.

Thx for closing, didn’t know how to mark as resolved without an answer ^^

No problem :smiley:

… ummm … but same issue here:

.h
	UPROPERTY(EditAnywhere)
		UParticleSystem* PulseParticles;

.cpp

AMotionBomb::AMotionBomb()
{
	PulseParticles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("PulseParticle"));
	PulseParticles->SetAttachement(BombMesh);
	PulseParticles->SetRelativeLocation(FVector(0.f, 0.f, 50.f));

}

and error code:
CompilerResultsLog: Error: D:\temp\ue4-samples\Cookbook\Source\Cookbook\Private\MotionBomb.cpp(32) :
error C2440: ‘=’: cannot convert from ‘UParticleSystemComponent *’ to ‘UParticleSystem *’

here are my headers in .h file

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SphereComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Runtime/Engine/Classes/GameFramework/Character.h"
#include "Runtime/Engine/Classes/Particles/ParticleSystemComponent.h"
#include "ParticleHelper.h"
#include "Particles/ParticleSystem.h"
#include "Particles/ParticleSystemComponent.h"
#include "MotionBomb.generated.h"

whats wrong in my code ? …

Please open a new question.

It’s not the same issue btw, you are trying to assign a UParticleSystemComponent to a UParticleSystem, this is not a crash just bad code that does not compile. Try setting your property to UParticleSystemComponent