【问题标题】:Unreal Engine 5 crashing after using SetupAttachment function使用 SetupAttachment 函数后虚幻引擎 5 崩溃
【发布时间】:2021-10-06 12:10:09
【问题描述】:

我创建了新项目并添加了新的 c++ 类,但在使用 SetupAttachment UE 后出现错误。我试图修复它并找到了一个问题。现在我不知道,在什么问题上,我实际上知道这个地方。 UE5 window after building

代码:

标题:

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

#pragma once

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

class USpringArmComponent;
class UCameraComponent;

UCLASS()
class TANKS_API ATankController : public APawn
{
    GENERATED_BODY()

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

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

    //DEFINTE COMPONENTS //

    // Do a Hull of the Tank
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* Hull;

    // Wheels for the Tank
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* Wheel1;
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* Wheel2;

    //Tower of the Tank
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* Turret;
  
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* Barrel;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UStaticMeshComponent* RecoilSystem;

    // Camera Components

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    USpringArmComponent* SpringArm;
  
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
    UCameraComponent* Camera;

public: 

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

};

还有 cpp:

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


#include "TankController.h"

#include "GameFramework/SpringArmComponent.h"

// Sets default values
ATankController::ATankController()
{
    // 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;

    // Set Root Component to ours Hull
    RootComponent = Hull;

    // Attach Wheels to the Hull
    // Here i have an error
    SpringArm->SetupAttachment(Hull);

}

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

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

}

如何解决这个错误? 是我的错误,还是 UE 的 bug?

【问题讨论】:

    标签: c++ crash unreal-engine4 unrealscript


    【解决方案1】:

    这是你的错。你永远不会初始化SpringArm,即使它是在你的actor实例中设置的(或通过蓝图或子类),它在构造函数期间也不可用(并且在构造CDO时仍然会崩溃)。

    【讨论】:

      猜你喜欢
      • 2017-09-20
      • 2020-07-24
      • 2017-07-18
      • 2017-09-10
      • 2019-06-18
      • 1970-01-01
      • 2020-03-24
      • 2020-06-02
      • 2022-06-13
      相关资源
      最近更新 更多