0

According to the unreal documentation, GetRelativeRotation is a member variable of USceneComponent. However, when I run my code, it tells me that it's not. I have tried switching my Camera to a UCameraComponent(as it was originally before I checked the documenation) and still no luck. Any ideas? heres the code for the .cpp file:

#include "FirstPersonCharacter.h"

AFirstPersonCharacter::AFirstPersonCharacter()
{

    PrimaryActorTick.bCanEverTick = true;

    AutoPossessPlayer = EAutoReceiveInput::Player0;

    bUseControllerRotationYaw = false;

    Cam = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Cam->AttachTo(RootComponent);
    Cam->SetRelativeLocation(FVector(0.f, 0.f, 40.f)); //places the camera 40cm above the centre of the body.

}

void AFirstPersonCharacter::BeginPlay()
{
    Super::BeginPlay();
    
}

void AFirstPersonCharacter::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

void AFirstPersonCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    InputComponent->BindAxis("HorizontalMovement", this, &AFirstPersonCharacter::HorizontalMove);
    InputComponent->BindAxis("VerticalMovement", this, &AFirstPersonCharacter::VerticalMove);
    InputComponent->BindAxis("VerticalLook", this, &AFirstPersonCharacter::VerticalRot);
    InputComponent->BindAxis("HorizontalLook", this, &AFirstPersonCharacter::HorizontalRot);
}

void AFirstPersonCharacter::HorizontalMove(float value)
{
    if (value) //make sure it doesn't constantly call on addmovementinput if theres no value to add to it
    {
        AddMovementInput(GetActorRightVector(), value); 
    }
}

void AFirstPersonCharacter::VerticalMove(float value)
{
    if (value) //make sure it doesn't constantly call on addmovementinput if theres no value to add to it
    {
        AddMovementInput(GetActorForwardVector(), value);
    }
}

void AFirstPersonCharacter::HorizontalRot(float value)
{
    if (value)
    {
        AddActorLocalRotation(FRotator(0, value, 0));
    }
}

void AFirstPersonCharacter::VerticalRot(float value)
{
    if (value)
    {
        float temp = Cam->GetRelativeRotation().Pitch + value; //THIS IS WHERE THE ISSUE IS
        if (temp < 65 && temp > -65)
        {
            Cam->AddLocalRotation(FRotator(value, 0, 0));
        }
}

and the code for the header file:

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Components/InputComponent.h"
#include "Components/SceneComponent.h"
#include "Camera/CameraComponent.h"
#include "FirstPersonCharacter.generated.h"

UCLASS()
class MOMENTUMPROJECTMAIN_API AFirstPersonCharacter : public ACharacter
{
    GENERATED_BODY()

public:
    // Sets default values for this character's properties
    AFirstPersonCharacter();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public: 
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    // Called to bind functionality to input
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    

private:
    void HorizontalMove(float value);
    void VerticalMove(float value);
    void HorizontalRot(float value);
    void VerticalRot(float value);

    //allows me to edit in the editor, without going into source code.
    UPROPERTY(EditAnywhere, Category = "Camera")
        UCameraComponent* Cam;
        
};

thanks.

  • 1
    What's the error it gave you? –  Nov 08 '20 at 21:32
  • Sorry. It told me that UCameraComponent/USceneComponent(no matter which I put) has no member GetRelativeRotation. – jacobpearson25 Nov 08 '20 at 21:33
  • Are you sure Cam is of the type USceneComponent? –  Nov 08 '20 at 21:35
  • I declared it as that type originally, and then also tried UCameraComponent to make sure. Neither worked. It is in the Header file. – jacobpearson25 Nov 08 '20 at 21:36
  • Could it be that the documentation you read is obsolete? –  Nov 08 '20 at 21:38
  • I assumed that was the case, but that was the only documentation on the topic. I also watched a video with someone attempting the same thing back in February of this year, and it worked perfectly for them. That's why I'm so confused about the whole thing. – jacobpearson25 Nov 08 '20 at 21:39
  • By the way, you are missing a `}` in `void AFirstPersonCharacter::VerticalRot(float value)` –  Nov 08 '20 at 21:40
  • Thanks for pointing that out, but it's still not the main problem. Still saying that its not a member. Strange. Might have to write a whole new set of code to try and bypass that single line. – jacobpearson25 Nov 08 '20 at 21:43
  • You could try to use another method of Cam, before GetRelativeRotation runs. Then if there is an error in that new line, you know the problem isn't in the GetRelativeRotation call. –  Nov 08 '20 at 21:50
  • Yeah, the new line worked fine, so I think it was the GetRelativeRotation call that was the issue. I've replaced it with GetComponentRotation (which is apparantly something I didn't see before) so am going to try that now. Thanks for the help! – jacobpearson25 Nov 08 '20 at 21:57
  • My 4.25.4 and 4.26 Preview 6 both had GetRelativeRotation() as a function of CameraComponent. Was it a Intellisense error or a compiler error? If it compiles fine then your Intellisense is misconfigured. – boocs Nov 09 '20 at 05:54
  • Had an error with both. Even when I compiled, Unreal told me the issue was that as well. – jacobpearson25 Nov 09 '20 at 22:13
  • I copied your code to a new 4.25.4 project and it had no Intellisense errors and it also compiled without errors. The only thing I fixed was the missing } and removed MOMENTUMPROJECTMAIN_API since I don't have it. Pretty strange. – boocs Nov 11 '20 at 07:29
  • One thing I'd recommend is to, close UE4, then go into your project folder and right click on your uproject file. Choose Generate Visual Studio Project Files.. – boocs Nov 11 '20 at 08:14

0 Answers0