Player wont move at all when its location changes. Why is this?


The move tool you see circeled can move anywhere and the players body and camera wont follow. I have never had this issue before, no idea why now?

cpp file

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


#include "PlayerPawn.h"

#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/SceneComponent.h"

// Sets default values
APlayerPawn::APlayerPawn()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	RootComponent = Root;

	SkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));

	CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule"));
	CapsuleComponent->SetupAttachment(SkeletalMesh);

	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));

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


}

// Called when the game starts or when spawned
void APlayerPawn::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void APlayerPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}


.h file

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PlayerPawn.generated.h"

UCLASS()
class SURVIVALGAME_API APlayerPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	APlayerPawn();

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:

	UPROPERTY(EditAnywhere)
		class UCapsuleComponent* CapsuleComponent;
	UPROPERTY(EditAnywhere)
		class USkeletalMeshComponent* SkeletalMesh;
	UPROPERTY(VisibleAnywhere)
		class USpringArmComponent* SpringArm;
	UPROPERTY(VisibleAnywhere)
		class UCameraComponent* Camera;
	UPROPERTY(VisibleAnywhere)
		class USceneComponent* Root;
};

Does anyone know why this is and how to fix it? I tested the same components in BP instead of C++ and it worked fine.

What’s the mesh attached to?

Its not attatched to anything, but I asume it is autimaticly attatched to the root. If I attatch it to the root in code nothing changes.

Does the same happen in a new project?

It doesn’t happen in a new project. Do you know why?

Wait it does now after a while it seems. I created another new project and have got the same problem. Mesh and all the rest of the components want to stay at 0, 0, 0. Origin point moves but nothing follows.

And this is with a scene root component and everything childed under that?

Yes they are all attached like a chain. I created a new derived BP class and the image looked normal compared to the one with the problem. The original class now has this pop up.
image
image
The new one seems to work now. I have no idea because I didn’t change anything.
Do you know why this is?

After a while(I think a restart) the new one has the same error(blueprint could not be loaded) for some reason. I recopiled and it didn’t change anything. When I restarted and recompiled it started working again. But this kind of thing keeps happerning it seems with new classes. Not sure what the cause is.
Any idea?

Not a clue, sorry.

Ok well thank you.

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

Privacy & Terms