You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unreal Engine调用MoveWindowTo遇arm64架构符号未定义错误求助

解决Unreal Engine中SWindow::MoveWindowTo链接错误的步骤

错误原因分析

编译时出现的undefined symbols for architecture arm64属于链接错误,说明项目未正确链接包含SWindow::MoveWindowTo实现的Slate模块;同时你在GameMode构造函数中调用窗口操作的时机过早,此时游戏窗口大概率还未完成初始化,即使链接正常也可能导致逻辑失效。


具体解决步骤

1. 添加Slate模块依赖

SWindow属于Unreal的Slate UI框架,需要在项目的Build配置中显式添加依赖:
找到项目目录下Source/[你的项目名]/[你的项目名].Build.cs,修改PublicDependencyModuleNames或PrivateDependencyModuleNames,加入Slate和SlateCore:

using UnrealBuildTool;

public class MyGame : ModuleRules
{
    public MyGame(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
    
        PublicDependencyModuleNames.AddRange(new string[] { 
            "Core", "CoreUObject", "Engine", "InputCore", 
            "Slate", "SlateCore" // 添加这两个模块
        });

        PrivateDependencyModuleNames.AddRange(new string[] {  });
    }
}

2. 调整窗口操作的执行时机

GameMode的构造函数是游戏启动的早期阶段,此时GameViewport的窗口尚未创建完成。将窗口移动逻辑放到BeginPlay()中,并通过延迟执行确保窗口初始化完成:

修改MyGameModeBase.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MyGameModeBase.generated.h"

UCLASS()
class MYGAME_API AMyGameModeBase : public AGameModeBase
{
    GENERATED_BODY()

public:
    AMyGameModeBase();
    // 重写BeginPlay函数
    virtual void BeginPlay() override;
};

修改MyGameModeBase.cpp

#include "MyGameModeBase.h"
#include "Engine/GameViewportClient.h"
#include "Widgets/SWindow.h"
#include "Kismet/GameplayStatics.h"

AMyGameModeBase::AMyGameModeBase()
{
    // 构造函数中不要放窗口操作逻辑
}

void AMyGameModeBase::BeginPlay()
{
    Super::BeginPlay();

    // 延迟1秒执行,确保窗口完全初始化
    FTimerHandle DelayTimer;
    GetWorld()->GetTimerManager().SetTimer(DelayTimer, [this]()
    {
        if (GEngine && GEngine->GameViewport)
        {
            TSharedPtr<SWindow> GameWindow = GEngine->GameViewport->GetWindow();
            if (GameWindow.IsValid())
            {
                FVector2D TargetPos = FVector2D(400.f, 300.f);
                GameWindow->MoveWindowTo(TargetPos);
            }
        }
    }, 1.0f, false);
}

3. 清理缓存并重新编译

链接错误常因旧缓存导致,执行以下操作彻底清理后重新编译:

  • 关闭Rider和Unreal Editor
  • 删除项目根目录下的Binaries、Intermediate、Saved文件夹
  • 右键项目的.uproject文件,选择Generate Visual Studio Project Files(Rider打开项目时会自动同步)
  • 重新编译项目

内容的提问来源于stack exchange,提问作者Beomjun Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 21:07:35