Unreal 中的本地空间定位点Local Spatial Anchors in Unreal


空间定位点用于在应用程序会话之间保存真实世界空间中的全息影像。Spatial anchors are used to save holograms in real-world space between application sessions. 这些是通过 Unreal 以 ARPin 的形式出现的,并保存在 HoloLens 定位点存储中以便在未来会话中加载。These get surfaced through Unreal as ARPin s and saved in the HoloLens’ anchor store, which is loaded in future sessions. 当没有 Internet 连接时,本地定位点是理想的备用方案。Local anchors are ideal as a fallback when there is no internet connectivity.


本地定位点存储在设备上,而 Azure 空间定位点存储在云中。Local anchors are stored on device, while Azure Spatial Anchors are stored in the cloud. 如果你想要使用 Azure 云服务来存储定位点,我们有一个文档可指导你如何集成 Azure 空间定位点If you're looking to use Azure cloud services to store your anchors, we have a document that can walk you through integrating Azure Spatial Anchors. 请注意,你可在同一项目中使用本地定位点和 Azure 定位点,不会发生冲突。Note that you can have local and Azure anchors in the same project without conflict.

检查定位点存储Checking the anchor store

在保存或加载定位点之前,需要检查定位点存储是否已准备就绪。Before saving or loading anchors, you need to check if the anchor store is ready. 在定位点存储准备就绪之前,调用任何 HoloLens 定位点函数都不会成功。Calling any of the HoloLens anchor functions before the anchor store is ready will not succeed.


保存定位点Saving anchors

一旦应用程序的一个组件需要固定到世界,它可以按照以下顺序保存到定位点存储:Once the application has a component that needs to be pinned to the world, it can be saved to the anchor store with the following sequence:


细分如下:Breaking this down:

  1. 在已知位置生成 Actor。Spawn an actor at a known location.

  2. 使用该位置和基于 Actor 的类的名称创建 ARPin。Create an ARPin with that location and a name based on the actor’s class.

  3. 将 Actor 添加到 ARPin并将引脚保存到 HoloLens 定位点存储。Add the actor to the ARPin and save the pin to the HoloLens anchor store.

    • 选择的定位点名称必须是唯一的,因此在本示例中是当前时间戳。The anchor name you choose must be unique, which in this example is the current timestamp.
  4. 如果定位点成功保存到定位点存储,则可以在 HoloLens 设备门户的“系统”>“映射管理器”>“设备上已保存的定位点文件”下检查定位点。If the anchor is successfully saved to the anchor store, you can be inspect it in the HoloLens device portal under System > Map manager > Anchor Files Saved On Device .

加载定位点Loading anchors

当应用程序启动时,可以使用以下蓝图将组件还原到其定位点位置:When an application starts, you can use the following blueprint to restore components to their anchor locations:


细分如下:Breaking this down:

  1. 循环访问定位点存储中的所有定位点。Iterate over all of the anchors in the anchor store.

  2. 按标识生成 Actor。Spawn an actor at identity.

  3. 将该 Actor 从定位点存储固定到 ARPin。Pin that actor to the ARPin from the anchor store.

    • 必须按标识生成 Actor,这一点很重要,因为定位点负责根据全息影像的保存位置在世界中重新定位全息影像。It's important to spawn the actor at identity since the anchor is responsible for repositioning the hologram in the world based on where it was saved. 因此,此处添加的任何变形都将增加定位点的偏移量。Any transform added here will add an offset to the anchor.

还将查询定位点 ID,以便根据定位点的保存名称来生成不同的 Actor。The anchor ID is also queried so that different actors can be spawned depending on the anchor’s saved name.

删除定位点Removing anchors

完成定位点后,可以使用“从 WMRAnchor 存储中删除 ARPin”和“从 WMRAnchor 存储中删除所有 ARPin”组件来清除单个定位点或整个定位点存储 。When you're done with an anchor you can clear individual anchors or the entire anchor store with the Remove ARPin from WMRAnchor Store and Remove All ARPins from WMRAnchor Store components.



请记住,空间定位点仍处于测试阶段,因此,请务必查看是否有更新的信息和功能。Bear in mind that Spatial Anchors are still in Beta, so be sure to check back for updated information and features.

下一个开发检查点Next Development Checkpoint

如果你遵循我们规划的 Unreal 开发检查点历程,则你处于探索 MRTK 核心构建基块的过程之中。If you're following the Unreal development checkpoint journey we've laid out, you're in the midst of exploring the MRTK core building blocks. 从这里,你可以进入下一个构建基块:From here, you can proceed to the next building block:

或跳转到混合现实平台功能和 API:Or jump to Mixed Reality platform capabilities and APIs:

你可以随时返回到 Unreal 开发检查点You can always go back to the Unreal development checkpoints at any time.

另请参阅See also