Session与Frame中getAll/Updated系列Trackables、Anchors方法的差异及适用场景咨询
Differences Between
Session.getAllTrackables() / Session.getAllAnchors() and Frame.getUpdatedTrackables() / Frame.getUpdatedAnchors() Awesome question—this is a common point of confusion when working with AR frameworks like ARCore or ARKit, so let’s break it down clearly. The pairs work identically for trackables and anchors, so we’ll cover both together.
What Each Method Returns
Session.getAllTrackables()/Session.getAllAnchors(): This gives you the entire collection of trackables/anchors the session has ever detected (and hasn’t been manually destroyed). Think of it as a full snapshot of every AR entity the system knows about—including ones that haven’t moved, changed, or been touched since the last frame.Frame.getUpdatedTrackables()/Frame.getUpdatedAnchors(): This only returns the subset of trackables/anchors that changed in the current frame. Changes can mean anything: newly detected, updated position/rotation, expanded plane bounds, or marked as no longer tracked.
Why Both Methods Exist
It all boils down to performance and efficiency:
- If you had to iterate through every single trackable every frame, even the static ones that never change, your app would waste a ton of processing power. The Frame methods let you skip all that noise and only focus on what’s actually different.
- The Session methods, on the other hand, give you a complete picture when you need it—like when you’re starting fresh or recovering from a pause, you can’t rely on just the latest frame’s updates to rebuild your entire AR scene.
When to Call Each
Reach for Session.getAllTrackables() / Session.getAllAnchors() when:
- You’re initializing your AR scene for the first time (e.g., loading saved anchors from a previous session).
- Your app resumes from the background—you’ll want to sync up with all the trackables the session retained while inactive.
- You’re resetting your AR session and need to rebuild all tracked content from scratch.
- You need a full, one-time snapshot of every AR entity at a specific moment.
Use Frame.getUpdatedTrackables() / Frame.getUpdatedAnchors() for:
- Your main frame-by-frame AR render loop. This is where you’ll handle new plane detections, adjust the position of virtual objects as their anchors update, or clean up trackables that the system has stopped tracking.
- Any time you only care about reacting to changes, not reprocessing every known entity.
Quick Real-World Example
Say you’re building an AR home decor app:
- When the app launches, you call
Session.getAllAnchors()to load any saved couch/table anchors the user placed in a previous session. - Every frame, you use
Frame.getUpdatedTrackables()to catch new wall/floor planes, adjust your virtual lamp’s position as the plane’s bounds refine, and remove any planes the system can no longer see.
内容的提问来源于stack exchange,提问作者redpearl
相关产品推荐
相关产品推荐

