歌德之殇
2022-02-23 16:50
采纳率: 0%
浏览 27

UE4 C++转换蓝图调用添加的关键代码报错,想要调节UE画面尺寸不让UI遮盖了他

UE4 C++转换蓝图调用添加的关键代码报错,想要调节UE画面尺寸不让UI遮盖了他

问题遇到的现象和发生背景

UE4 ,我想用别人给的方法修改UE显示画面,用于制作设计类软件,需求是UI不能遮盖画面,所以参考别人给的 调节视图代码。但是我继承GameModeBase重写添加本方法并且添加了 UFUNCTION(BlueprintCallable, Category = "Adjust") 的符号后 编译就报错,因为不添加编译是不报错的。

问题相关代码,请勿粘贴截图

MyWindowsGameModeBase.h代码

//#include "Margin.h"
//#include "Object.h"
#include "Engine.h"
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MyWindowsGameModeBase.generated.h"

UCLASS()
class CJJPROJECTTEST_API AMyWindowsGameModeBase : public AGameModeBase
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category = "Adjust")
     void AdjustViewportSize(UObject* WorldObjectContext, FMargin margin);
};

MyWindowsGameModeBase.cpp代码:

#include "MyWindowsGameModeBase.h"

void AMyWindowsGameModeBase::AdjustViewportSize(UObject* WorldObjectContext, FMargin margin)
{
   // UE_LOG(LogTemp, Log, TEXT(" AdjustViewportSize "));
    if (WorldObjectContext->GetWorld() &&
        /*GetWorld()->WorldType == EWorldType::Game &&*/
        GEngine && GEngine->GameViewport)
    {
        FVector2D ViewportSize;
        GEngine->GameViewport->GetViewportSize(ViewportSize);
        // The GameViewport takes some time to initialize
        if (ViewportSize.X > 0 && ViewportSize.Y > 0)
        {
            FMargin relativeMat = FMargin
            {
                margin.Left / ViewportSize.X    ,
                margin.Top / ViewportSize.Y    ,
                1 - margin.Right / ViewportSize.X    ,
                1 - margin.Bottom / ViewportSize.Y
            };
            GEngine->GameViewport->SplitscreenInfo[0].PlayerData[0].OriginX = relativeMat.Left;
            GEngine->GameViewport->SplitscreenInfo[0].PlayerData[0].OriginY = relativeMat.Top;
            GEngine->GameViewport->SplitscreenInfo[0].PlayerData[0].SizeX = relativeMat.Right;
            GEngine->GameViewport->SplitscreenInfo[0].PlayerData[0].SizeY = relativeMat.Bottom;
        }
    }
}

运行结果及报错内容
无法解析的外部符号 "__declspec(dllimport) class UScriptStruct * __cdecl Z_Construct_UScriptStruct_FMargin(void)" (__imp_?Z_Construct_UScriptStruct_FMargin@@YAPEAVUScriptStruct@@XZ),函数 "void __cdecl `dynamic initializer for 'public: static struct UE4CodeGen_Private::FStructPropertyParams const Z_Construct_UFunction_AMyWindowsGameModeBase_AdjustViewportSize_Statics::NewProp_margin''(void)" (??__E?NewProp_margin@Z_Construct_UFunction_AMyWindowsGameModeBase_AdjustViewportSize_Statics@@2UFStructPropertyParams@UE4CodeGen_Private@@B@@YAXXZ) 中引用了该符号    

3条回答 默认 最新

相关推荐 更多相似问题