Coming up with a problem, I’ve set up a custom Pawn child class named X. It allows me to compile no problem, but when I create a child BP class based on this pawn class, it keeps crashing the editor with Access violation reading location 0x0000000000000520. This happens when I click the Open in full view editor once the BP is created. Not sure why. The break point on this warning is on GENERATED_BODY() which makes me think it’s related to components hierarchy.
X.h:
#pragma once
#include "GameFramework/Pawn.h"
#include "CableComponent.h"
#include "X.generated.h"
UCLASS()
class TUX_087_API AX : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AX();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// Behavior
UPROPERTY(EditAnywhere, Category = "Behavior")
class UBehaviorTree* HangingMaruta_Behavior;
/// Components ///
// Scene
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USceneComponent* Scene;
// Stable end of Constraint
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UStaticMeshComponent* EndofChain;
// HangingMaruta Mesh
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UStaticMeshComponent* HangingMaruta;
// Physics Constraint
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UPhysicsConstraintComponent* Constraint;
// Grab Trigger
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UBoxComponent* ActionTrigger;
// EndGrabTrigger
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USphereComponent* EndGrabTrigger;
// Cable
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UCableComponent* Cable;
// SpotLight
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USpotLightComponent* Light;
/// Variables ///
// Is The Maruta already grabbing a target?
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
bool bIsGrabbingTarget;
// Is the player within Range?
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
bool bPlayerIsInRange;
// New Clamped MaxWalkSpeed Value
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
float NewMaxWalkSpeed;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "CharacterRef")
class AMyCharacterTest* CharacterRef;
// Grab Ability Cooldown Timer handle
FTimerHandle TimerHandle_GrabAbilityCD;
X.cpp:
#include "TUX_087.h"
#include "X_AIController.h"
#include "MyCharacterTest.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BlackboardComponent.h"
#include "Runtime/Engine/Classes/PhysicsEngine/PhysicsConstraintComponent.h"
#include "Runtime/Engine/Classes/PhysicsEngine/PhysicsConstraintActor.h"
#include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h"
#include "Runtime/Core/Public/Math/UnrealMathUtility.h"
#include "CableComponent.h"
#include "X.h"
// Sets default values
AX::AX()
{
// 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;
AIControllerClass = AX_AIController::StaticClass();
// Create Components
Scene = CreateDefaultSubobject<USceneComponent>("Scene");
EndofChain = CreateDefaultSubobject<UStaticMeshComponent>("EndofChain");
X= CreateDefaultSubobject<UStaticMeshComponent>("HangingMaruta");
Constraint = CreateDefaultSubobject<UPhysicsConstraintComponent>("Constraint");
ActionTrigger = CreateDefaultSubobject<UBoxComponent>("Trigger");
Cable = CreateDefaultSubobject<UCableComponent>("Cable");
EndGrabTrigger = CreateDefaultSubobject<USphereComponent>("EndTrigger");
Light = CreateDefaultSubobject<USpotLightComponent>("Light");
Scene->bAbsoluteRotation = true;
// Set Root
RootComponent = Scene;
// Attach RootComponent Child Components.
EndofChain->SetupAttachment(RootComponent);
X->SetupAttachment(RootComponent);
Constraint->SetupAttachment(RootComponent);
EndGrabTrigger->SetupAttachment(RootComponent);
// Attach XChild Components.
ActionTrigger->SetupAttachment(HangingMaruta);
Cable->SetupAttachment(HangingMaruta);
HangingMaruta->SetSimulatePhysics(true);
// Attach EndofChain Child Components.
Light->SetupAttachment(EndofChain);
// Add overlapping event on Trigger
ActionTrigger->OnComponentBeginOverlap.AddDynamic(this, &AX::SetTarget);
ActionTrigger->OnComponentEndOverlap.AddDynamic(this, &AX::ResetTarget);
EndGrabTrigger->OnComponentEndOverlap.AddDynamic(this, &AX::DetachTarget);
// Clamp Max Walk Speed value
//NewMaxWalkSpeed = 600.f;
}