The springarm does not move

I want to move the springarm to the top to raise the field of view. But the springarm won’t move.


// Fill out your copyright notice in the Description page of Project Settings.

#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Tank.h"

ATank::ATank(){
    USpringArmComponent* SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
    SpringArm->SetupAttachment(RootComponent);
    //RootComponent = BasePawn의 CapsuleComp

    UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Camera->SetupAttachment(SpringArm);
}

void ATank::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) {
    //상위 버전 호출
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);

}

void ATank::Move(float Value){
    UE_LOG(LogTemp,Warning,TEXT("Value : %f"),Value);
}
// Fill out your copyright notice in the Description page of Project Settings.

//중복 방지
#pragma once

#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tank.generated.h"

/**
 * 
 */
UCLASS()					//BasePawn클래스 상속함
class TOONTANKS_API ATank : public ABasePawn
{
	GENERATED_BODY()

public:
	ATank();

	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
	UPROPERTY(VisibleAnywhere, Category = "Components")
	class UCameraComponent* CameraComponent;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	class USpringArmComponent* SpringComponent;

	void Move(float Value);

};

And in the lecture, when I declared SpringArm and Camera, I didn’t make a Type Declaration before. But because I didn’t make a Type Declaration, I had a problem and made a voluntary declaration, but why didn’t I declare it in the lecture?
질문 1
.

They have to be declared in the header. This is required so that you can set the UPROPERTY(VisibleAnywhere) so you can edit them.

Are you saying to do UPROPERTY (VisibleAnywhere) to move the springarm?

Yes, but also you have to add the Declaration in the header, not in the constructor. Look at the end of lecture code to see what I mean.

In the header Tank.h you have to have:

UPROPERTY(VisibleAnywhere)
USpringArmComponent* SpringArm;

UPROPERTY(VisibleAnywhere)
UCameraComponent* Camera;

in your ATank::ATank(), you still create them and attach them but you don’t declare them

You made a name mistake. I didn’t notice this. Thank you for your kind reply. It works properly.

Definitely possible. I typed from memory. The editor would have told me when I was entering something wrong.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms