Declaring a ParticleSystemComponent

I’m trying to declare a Particle System Component in my code, but for some reason it keeps telling me

“Cannot Convert UParticleSystemComponent to UObject”

I believe I maybe declaring it wrong, but I would like to know how to declare the particle :frowning:

.h file

 // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
    #pragma once
    #include "SideScrollerConceptCharacter.generated.h"
    class ASideScrollerConceptCharacter : public ACharacter
    	/** Side view camera */
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    	TSubobjectPtr<UCameraComponent> SideViewCameraComponent;
    	/** Camera boom positioning the camera beside the character */
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    	TSubobjectPtr<class USpringArmComponent> CameraBoom;

    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Particle)
    	TSubobjectPtr<class UParticleSystemComponent> Ability_l;

    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Particle)
    	TSubobjectPtr<class UParticleSystemComponent> Ability_r;
    	virtual void BeginPlay();
    	/** Called for side to side input */
    	void MoveRight(float Val);
    	/** Handle touch inputs. */
    	void TouchStarted(const ETouchIndex::Type FingerIndex, const FVector Location);
    	// APawn interface
    	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) OVERRIDE;
    	// End of APawn interface

.CPP file

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
    #include "SideScrollerConcept.h"
    #include "SideScrollerConceptCharacter.h"
    ASideScrollerConceptCharacter::ASideScrollerConceptCharacter(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    	// Set size for collision capsule
    	CapsuleComponent->InitCapsuleSize(42.f, 96.0f);
    	// Don't rotate when the controller rotates.
    	bUseControllerRotationPitch = false;
    	bUseControllerRotationYaw = false;
    	bUseControllerRotationRoll = false;
    	// Create a camera boom attached to the root (capsule)
    	CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
    	CameraBoom->bAbsoluteRotation = true; // Rotation of the character should not affect rotation of boom
    	CameraBoom->TargetArmLength = 500.f;
    	CameraBoom->SocketOffset = FVector(0.f,0.f,75.f);
    	CameraBoom->RelativeRotation = FRotator(0.f,180.f,0.f);
    	// Create a camera and attach to boom
    	SideViewCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("SideViewCamera"));
    	SideViewCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
    	SideViewCameraComponent->bUseControllerViewRotation = false; // We don't want the controller rotating the camera
    	// Configure character movement
    	CharacterMovement->bOrientRotationToMovement = true; // Face in the direction we are moving..
    	CharacterMovement->RotationRate = FRotator(0.0f, 720.0f, 0.0f); // this rotation rate
    	CharacterMovement->GravityScale = 2.f;
    	CharacterMovement->AirControl = 0.80f;
    	CharacterMovement->JumpZVelocity = 1000.f;
    	CharacterMovement->GroundFriction = 3.f;
    	CharacterMovement->MaxWalkSpeed = 600.f;
    	CharacterMovement->MaxFlySpeed = 600.f;

    	Ability_l = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("Ability_l"));
        Ability_r = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("Ability_r"));

    	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
    	// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
    void ASideScrollerConceptCharacter::BeginPlay()
    	CameraBoom->TargetArmLength = 700.0f;
    // Input
    void ASideScrollerConceptCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
    	// set up gameplay key bindings
    	InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
    	InputComponent->BindAxis("MoveRight", this, &ASideScrollerConceptCharacter::MoveRight);
    	InputComponent->BindTouch(IE_Pressed, this, &ASideScrollerConceptCharacter::TouchStarted);
    void ASideScrollerConceptCharacter::MoveRight(float Value)
    	// add movement in that direction
    	AddMovementInput(FVector(0.f,-1.f,0.f), Value);
    void ASideScrollerConceptCharacter::TouchStarted(const ETouchIndex::Type FingerIndex, const FVector Location)
    	// jump on any touch

CreateDefaultSubobject returns a pointer to an instance of ComponentClass, so I think you’re rather looking for

TSubobjectPtr<UParticleSystemComponent> Ability_l;

(i.e. without “class” )

I tried that as well still the same error.

1>c:\unrealengine-4.0.2-release\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(566): error C2440: 'initializing' : cannot convert from 'UParticleSystemComponent *' to 'UObject *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>          c:\unrealengine-4.0.2-release\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(564) : while compiling class template member function 'TSubobjectPtrConstructor<UParticleSystemComponent>::TSubobjectPtrConstructor(SubobjectType *)'
1>          with
1>              SubobjectType=UParticleSystemComponent
1>          ]
1>          c:\unrealengine-4.0.2-release\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(679) : see reference to function template instantiation 'TSubobjectPtrConstructor<UParticleSystemComponent>::TSubobjectPtrConstructor(SubobjectType *)' being compiled
1>          with
1>              SubobjectType=UParticleSystemComponent
1>          ]

this is what the output window is giving me when I build the code. I was curious if there is a different way to declare the ParticleSystemComponent?

You might be missing an include. Try including “ParticleDefinitions.h” in your cpp.

Michael Noland

That worked!! :D!

Thank You Michael!! :slight_smile: