strange - I’m in 4.16.1 - I can compile, but while running, I get the error:
PIE:Error: Error Blueprint Runtime Error: Accessed None trying to read property TankMovementComponent from function: ‘ExecuteUbergraph_Tank_BP’ from node: Intend Move Forward in graph: InputSetup in object: Tank_BP with description: Accessed None trying to read property TankMovementComponent
Any ideas?
Code below:
TankMovementComponent.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/NavMovementComponent.h"
#include "TankMovementComponent.generated.h"
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class BATTLETANK_API UTankMovementComponent : public UNavMovementComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Input)
void IntendMoveForward(float Throw);
private:
};
TankMovementComponent.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BattleTank.h"
#include "TankMovementComponent.h"
void UTankMovementComponent::IntendMoveForward(float Throw)
{
UE_LOG(LogTemp, Warning, TEXT("Intend Move Forward %f"), Throw)
}
Tank.h
UCLASS()
class BATTLETANK_API ATank : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ATank();
...
UFUNCTION(BlueprintCallable, Category = Firing)
void Fire();
protected:
UPROPERTY(BlueprintReadOnly)
UTankMovementComponent* TankMovementComponent = nullptr;
...
Tank.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BattleTank.h"
#include "TankAimingComponent.h"
#include "TankMovementComponent.h"
#include "Tank.h"
#include "TankTrack.h"
#include "TankBarrel.h"
#include "TankTurret.h"
#include "Projectile.h"
// Sets default values
ATank::ATank()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false; // temp false? true;
TankAimingComponent = CreateDefaultSubobject<UTankAimingComponent>(FName("Aiming Component"));
TankMovementComponent = CreateDefaultSubobject<UTankMovementComponent>(FName("Movement Component"));
}