I'm having problems with UUserWidgets on UE5

Tec*_*nut 1 c++ linker unreal-engine5

I'm following a tutorial on user widgets and after I add TSubclassOf<UUserWidget> widgetClass; it gives me an error I can't figure it out:

MainPlayer.gen.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class UClass * __cdecl Z_Construct_UClass_UUserWidget_NoRegister(void)" (__imp_?Z_Construct_UClass_UUserWidget_NoRegister@@YAPEAVUClass@@XZ) referenced in function "void __cdecl `dynamic initializer for 'public: static struct UECodeGen_Private::FClassPropertyParams const Z_Construct_UClass_AMainPlayer_Statics::NewProp_widgetClass''(void)" (??__E?NewProp_widgetClass@Z_Construct_UClass_AMainPlayer_Statics@@2UFClassPropertyParams@UECodeGen_Private@@B@@YAXXZ)"
Run Code Online (Sandbox Code Playgroud)

the img:https://i.stack.imgur.com/VKGZO.png

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

#pragma once

#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Blueprint/UserWidget.h"
#include "MainPlayer.generated.h"

UCLASS()
class SURVIVAL_GAME_API AMainPlayer : public ACharacter
{
    GENERATED_BODY()

public:
    // Sets default values for this character's properties
    AMainPlayer();

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;


    

public:

    //Movement and interactions

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Camera")
    UCameraComponent* myCamera;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
    USpringArmComponent* mySprigArm;

    UFUNCTION()
    void moveForward(float value);
    
    UFUNCTION()
    void moveRight(float value);

    UFUNCTION()
    void lookUp(float value);

    UFUNCTION()
    void lookRight(float value);

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character")
    float movementSpeed;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character")
    float sensitivity;

    UFUNCTION()
    void interact();

    UFUNCTION()
    void toggleInventory();
    // 

    //Variables

protected:
    UPROPERTY(EditAnywhere, Category = "Variables")
    TSubclassOf<UUserWidget> widgetClass;

    

    //
};
Run Code Online (Sandbox Code Playgroud)

Dim*_*gin 11

有点晚了,但万一你还没有解决它......
我的猜测是该UMG模块没有添加到PublicDependencyModuleNames.

您需要将其添加到your_progect_name.build.cs文件中:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore"});
Run Code Online (Sandbox Code Playgroud)

将模块名称添加到列表中,在本例中UMG:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG"});
Run Code Online (Sandbox Code Playgroud)

它应该解决尚未解决的外部问题。

  • 我什至更晚,但我确实想让你知道我狩猎了两天,这为我解决了问题。谢谢你!:) (2认同)