Announcement

Collapse
No announcement yet.

Calling Variable from another class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Code:
    1>c:\users\chadalak\documents\unreal projects\sidescrollerconcept\source\sidescrollerconcept\natureability.cpp(22): error C2220: warning treated as error - no 'object' file generated
    1>c:\users\chadalak\documents\unreal projects\sidescrollerconcept\source\sidescrollerconcept\natureability.cpp(22): warning C4700: uninitialized local variable 'SizeCheck' used
    Maybe I'm declaring the object wrong? Here's my code

    .cpp
    Code:
    #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

    Code:
    
    #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;
    	
    };
    Portfolio/Tutorials: http://chadreddick.com

    #2
    The error says "uninitialized local variable 'SizeCheck' used". I don't see that you are initializing SizeCheck before calling ChargeAmount on it.

    Code:
    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.

    Comment


      #3
      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.
      Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
      Twitter: @EpicJamesG

      Comment


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

        SideScrollerConceptCharacter.cpp
        Code:
        	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).
        Last edited by CHADALAK1; 04-10-2014, 10:35 AM.
        Portfolio/Tutorials: http://chadreddick.com

        Comment

        Working...
        X