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

如何在Widget与Level Blueprint间通信?含重启按钮及Player Start获取问题

解决Widget重启按钮通知Level Blueprint及获取Player Start的问题

一、点击Widget按钮通知Level Blueprint

这里给两个实用方案:

方案1:使用蓝图接口(Blueprint Interface)

  • 新建一个蓝图接口,命名为I_RestartLevelInterface,添加一个纯虚函数OnRestartRequested
  • 打开Level Blueprint,在类设置里勾选实现这个接口,然后在接口函数内编写重启关卡、重置玩家位置的逻辑
  • 在Widget Blueprint的按钮点击事件中,通过Get World -> Get Level Actor获取当前关卡的Level Actor,将其强制转换为I_RestartLevelInterface类型后,调用OnRestartRequested函数

方案2:直接传递Widget引用给Level Blueprint

  • 在Level Blueprint中创建变量RestartWidgetRef,类型设为你的Widget类,开启**可编辑(Editable)**属性
  • 当你创建并显示Widget时,把Widget的引用赋值给Level Blueprint的RestartWidgetRef变量
  • 在Widget的按钮点击事件里,通过RestartWidgetRef直接调用Level Blueprint中提前定义好的**可调用(Callable)**重启函数

二、获取Player Start对象

Widget不适合直接检索场景对象,更高效的方式是由Level Blueprint提前传递引用:

  • 在Level Blueprint中,用Get All Actors of Class节点选择PlayerStart类,获取目标Player Start对象(比如取列表第一个)
  • 将这个Player Start的引用传递给Widget:可以通过Widget的自定义变量接收,或者在创建Widget时通过构造参数传入
  • 如果一定要在Widget内直接获取,也可以用Get World -> Get All Actors of Class节点筛选PlayerStart类,但大场景下这种方法效率偏低,不推荐

重启关卡的核心逻辑可以用Restart Level节点(UE5)或Open Level节点(指定当前关卡名称),重置玩家位置时直接将玩家Pawn的Location设为Player Start的Location即可。

内容的提问来源于stack exchange,提问作者darcy stabler

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 00:38:09