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
.h file
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "SideScrollerConceptCharacter.generated.h"
UCLASS(config=Game)
class ASideScrollerConceptCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
/** 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();
protected:
/** 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->AttachTo(RootComponent);
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); // ...at 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
Jump();
}