Calling Variable from another class

I’m having an issue where it wont accept the object declaration from my class. I want to get a variable from it, but it gives me this error.



1>c:\users\chadalak\documents\unreal projects\sidescrollerconcept\source\sidescrollerconcept
atureability.cpp(22): error C2220: warning treated as error - no 'object' file generated
1>c:\users\chadalak\documents\unreal projects\sidescrollerconcept\source\sidescrollerconcept
atureability.cpp(22): warning C4700: uninitialized local variable 'SizeCheck' used


Maybe I’m declaring the object wrong? Here’s my code

.cpp




#include "SideScrollerConcept.h"
#include "NatureAbility.h"
#include "ParticleDefinitions.h"
#include "SideScrollerConceptCharacter.h"


ANatureAbility::ANatureAbility(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	ProjectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComp"));
	ProjectileMovement->InitialSpeed = 3000.0f;
	ProjectileMovement->MaxSpeed = 3000.0f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = true;
	ProjectileMovement->Bounciness = 0.3f;

	NatureScale = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("NatureScale"));
	ASideScrollerConceptCharacter *SizeCheck;
	NatureScale->SetRelativeScale3D(FVector(SizeCheck->ChargeAmount, SizeCheck->ChargeAmount, SizeCheck->ChargeAmount));
}



.h





#pragma once

#include "GameFramework/Actor.h"
#include "NatureAbility.generated.h"

/**
 * 
 */
UCLASS()
class ANatureAbility : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
	TSubobjectPtr<class UProjectileMovementComponent> ProjectileMovement;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
	TSubobjectPtr<class UParticleSystemComponent> NatureScale;
	
};



The error says “uninitialized local variable ‘SizeCheck’ used”. I don’t see that you are initializing SizeCheck before calling ChargeAmount on it.



ASideScrollerConceptCharacter *SizeCheck;
NatureScale->SetRelativeScale3D(FVector(***SizeCheck->ChargeAmount***, SizeCheck->ChargeAmount, SizeCheck->ChargeAmount))


I guess you will need to Spawn an instance of ASideScrollerConceptCharacter first and assign it to SizeCheck.

staticvoidlol is correct, currently the pointer SizeCheck is uninitialized. I think that rather than trying to access your Character from inside the Constructor, you probably want some function like InitAbility which takes the ASideScrollerConceptCharacter* and you can call after you spawn a NatureAbility.

So would it be better to spawn it from the SideScrollerConceptCharacter? Making it more like this?

SideScrollerConceptCharacter.cpp



	if (bIsNature)
	{
		ANatureAbility *SpawnNature = GetWorld()->SpawnActor<ANatureAbility>(NatureAbilityClass, SocketLoc, SocketRot, SpawnParams);
		if (SpawnNature)
		{
			SpawnNature->SetActorRelativeScale3D(FVector(ChargeAmount, ChargeAmount, ChargeAmount));
		}
	}


[EDIT]
I was trying to achieve a weapon charge ability so it would increase damage the bigger the charge. Thus what I was trying to do is get the scale of the Particle Projectile and make it the size of the ChargeAmount variable(which is a float).