Creating Components Via Code Issue

Hi there, sadly I’m having quite some problems in creating components via code… Sometimes SetupAttachment is not a member of UStaticMeshComponent, other times CreateDefaultSubobject doesn’t exist and it also happened that the class inheriting from APawn needed to inherit directly from UObject but even doing that would not fix the issue and the class is completely broken…
I use Rider for Unreal Engine, but the same issues apply to Visual Studio Community as well, I unistalled my version of Unreal Engine and tried installing versions 4.24, 4.25 and 4.26 but the same random issues apply to all of them…
I tried to start the project in c++ as well as blueprints mode but nothing changes…
I tried to create the class from unreal or from the IDE but nothing changes…
I made more than 10 different new projects testing this issues and these problems are just totally random and I believe is Unreal’s fault…
It happened that in some projects restarting the engine would work while in other projects just compiling the code from the IDE would work…
What should I do? Should I just create new projects until one works, can someone help me please?
I really don’t know what to do…

Are you sure these aren’t just issues Rider is flagging as errors and not actual compilation errors? Are you not able to compile?

Hi Dan, thanks for answering me. I’ve had the exact same issues on both Rider and Visual Studio and then I “resolved” just creating a new project and compiling the code with the editor closed, apparently Unreal was messing up in some way…
But now i’m having other random problems, namely it doesn’t recognize AddActorLocalOffset, I really don’t understand what’s wrong…
I tried to add AActor:: and ATankPawn:: to make it recognize those keywords but is no use at all…


You have defined a non-member function as you are missing ATankPawn::

1 Like

Here is my code:

// TankPawn.h

#pragma once

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

class UCameraComponent;
class USpringArmComponent;

UCLASS()
class TANKS_API ATankPawn : public ABasePawn
{
	GENERATED_BODY()

	public:

		ATankPawn();

		virtual void Tick(float) override;
		virtual void SetupPlayerInputComponent(class UInputComponent*) override;

	protected:

		virtual void BeginPlay() override;

	private:

		float MoveSpeed = 100.0f;
		float RotateSpeed = 100.0f;

		FVector MoveDirection = {0.0, 0.0, 0.0};
		FQuat RotateDirection = {0.0, 0.0, 0.0, 0.0};

		void CalculateMoveInput(float);
		void CalculateRotateInput(float);

		void Move();
		void Rotate();

		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, category="Components", meta=(AllowPrivateAccess="true"))
			USpringArmComponent* SpringArm = nullptr;

		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, category="Components", meta=(AllowPrivateAccess="true"))
			UCameraComponent* Camera = nullptr;
};


// TankPawn.cpp

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

ATankPawn::ATankPawn()
{
	SpringArm = CreateDefaultSubobject<USpringArmComponent>("Spring Arm");
	SpringArm->SetupAttachment(RootComponent);

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

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

void ATankPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

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

	PlayerInputComponent->BindAxis("Move Forward/Backward", this, &ATankPawn::CalculateMoveInput);
	PlayerInputComponent->BindAxis("Move Left/Right", this, &ATankPawn::CalculateRotateInput);
}

void ATankPawn::CalculateMoveInput(float Value)
{
	MoveDirection = FVector(Value * MoveSpeed * GetWorld()->DeltaTimeSeconds, 0, 0);
}

void ATankPawn::CalculateRotateInput(float Value)
{
	RotateDirection = FQuat(0.0, 0.0, Value * RotateSpeed * GetWorld()->DeltaTimeSeconds, 0.0);
}

void Move()
{
	AddActorLocalOffset(MoveDirection, true); // problem here
}

void Rotate()
{
	AddActorLocalRotation(RotateDirection, true); // problem here
}

Can you explain what am I doing wrong?

These ae missing ATankPawn::, look at your other functions you’ve defined.

1 Like

Thank you very much, in my frustration I was completely blind to the problem…

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

Privacy & Terms