กำหนดค่าเซสชัน ARCore ด้วยส่วนขยาย ARCore สำหรับ Unity
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
กำหนดค่าเซสชัน ARCore เพื่อสร้างประสบการณ์ AR สําหรับแอป
เซสชันคืออะไร
กระบวนการ AR ทั้งหมด เช่น การติดตามการเคลื่อนไหว การทำความเข้าใจสภาพแวดล้อม และการประมาณแสงจะเกิดขึ้นภายในเซสชัน ARCore ARSession
คือจุดแรกเข้าหลักของ ARCore
API โดยจะจัดการสถานะระบบ AR และจัดการวงจรของเซสชัน ซึ่งช่วยให้แอปสร้าง กำหนดค่า เริ่ม หรือหยุดเซสชันได้ และที่สำคัญที่สุดคือช่วยให้แอปได้รับเฟรมที่อนุญาตให้เข้าถึงรูปภาพจากกล้องและท่าทางของอุปกรณ์
เซสชันนี้ใช้เพื่อกําหนดค่าฟีเจอร์ต่อไปนี้ได้
ตั้งค่าส่วนขยาย AR Foundation และ ARCore
คุณต้องตั้งค่า AR Foundation ก่อนจึงจะใช้ส่วนขยาย ARCore ได้ ดูวิธีการตั้งค่าฉาก AR ได้ที่เอกสารประกอบการตั้งค่า AR Foundation
คุณต้องตั้งค่าส่วนขยาย ARCore ก่อนจึงจะกำหนดค่าเซสชัน ARCore ได้ ดูเอกสารประกอบการตั้งค่าส่วนขยาย ARCore หากยังไม่ได้ดำเนินการ
สร้างการกำหนดค่าเซสชันใหม่ใน ARCore
ใน Unity ให้สร้างการกำหนดค่าเซสชันใหม่โดยไปที่ Assets >
Create > XR > ARCore Extensions Config
การกำหนดค่าเริ่มต้นจะมีลักษณะดังนี้

ในแผง Hierarchy ให้เลือกออบเจ็กต์ ARCore Extensions
ในช่อง ARCore Extensions Config ของแผง Inspector ให้คลิกปุ่ม
เป้าหมาย แล้วเชื่อมต่อกับชิ้นงาน ARCoreExtensionsConfig
การจัดการเซสชัน AR
ใน AR Foundation 2.1 และ 3.1 การทำลายออบเจ็กต์เกม ARSession จะทำลายเซสชัน ARCore ที่เกี่ยวข้อง
ตั้งแต่ AR Foundation 4.0 เป็นต้นไป คุณต้องใช้ฟังก์ชัน LoaderUtility
เพื่อทำลายและสร้างระบบย่อยแทน โปรดดูคำแนะนำในการย้ายข้อมูลจาก AR Foundation 3.x ไปยัง 4.x
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eAn ARCore session manages all AR processes like motion tracking and environmental understanding, and is accessed through the \u003ccode\u003eARSession\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eBefore configuring an ARCore session, ensure both AR Foundation and ARCore Extensions are properly set up in your Unity project.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure extension features within the ARCoreExtensionsConfig asset, which allows you to customize session behavior.\u003c/p\u003e\n"],["\u003cp\u003eStarting with AR Foundation 4.0, session management is handled through \u003ccode\u003eLoaderUtility\u003c/code\u003e functions instead of destroying the \u003ccode\u003eARSession\u003c/code\u003e game object.\u003c/p\u003e\n"],["\u003cp\u003eAfter configuring your session, explore the provided quickstart guides for Android and iOS to begin building AR experiences with ARCore Extensions.\u003c/p\u003e\n"]]],["An ARCore session is essential for AR processes like motion tracking and lighting estimation. `ARSession` manages the AR system state, including session creation and configuration, and enables access to camera images and device pose. Before configuring the ARCore session, AR Foundation and ARCore Extensions must be set up. You need to create an `ARCore Extensions Config` asset in Unity and connect it to the `ARCore Extensions` object. Session management is done using `LoaderUtility` functions in newer versions of AR Foundation.\n"],null,["# Configure an ARCore session with ARCore Extensions for Unity\n\nConfigure an ARCore session to build AR experiences for your app.\n\nWhat is a session?\n------------------\n\nAll [AR processes](/ar/discover/concepts), such as motion tracking,\nenvironmental understanding, and lighting estimation, happen inside an ARCore\nsession. [`ARSession`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.1/api/UnityEngine.XR.ARFoundation.ARSession.html) is the main entry point to the ARCore\nAPI. It manages the AR system state and handles the session lifecycle, allowing\nthe app to create, configure, start, or stop a session. Most importantly, it\nenables the app to receive frames that allow access to the camera image and\ndevice pose.\n\nThe session can be used to configure the following features:\n\n- [Cloud Anchors](/ar/develop/cloud-anchors)\n- [ARCore Geospatial API](/ar/develop/geospatial)\n\nSet up AR Foundation and ARCore Extensions\n------------------------------------------\n\nAR Foundation must be set up before you can use ARCore Extensions. See the\n[AR Foundation setup documentation](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.1/manual/index.html#scene-setup)\nfor instructions for setting up your AR scene.\n\nARCore Extensions must be set up before you can configure an ARCore session. See\nthe\n[ARCore Extensions setup documentation](/ar/develop/unity-arf/getting-started-extensions#setup_arcore_extensions) if you have not done so already.\n\nConfigure extension features in ARCoreExtensionsConfig\n------------------------------------------------------\n\nCreate a new session configuration in ARCore.\n\n1. In Unity, create a new session configuration by navigating to **Assets \\\u003e\n Create \\\u003e XR \\\u003e ARCore Extensions Config**.\n\n The default configuration looks like this:\n\n2. In the **Hierarchy** pane, select the **ARCore Extensions**\n object.\n\n3. In the **Inspector** pane's **ARCore Extensions Config** field,\n click the target\n\n button, and connect to the **ARCoreExtensionsConfig**\n asset.\n\nAR Session management\n---------------------\n\nIn [AR Foundation](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual) 2.1\nand 3.1 destroying the **ARSession** game object would destroy the underlying\nARCore session.\n\nStarting with AR Foundation 4.0, you must use the\n[`LoaderUtility`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.LoaderUtility.html)\nfunctions to destroy and create subsystems instead. See the AR Foundation\n[3.x to 4.x migration guide](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.1/manual/migration-guide-3.html).\n\n- [`LoaderUtility.Deinitialize()`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.LoaderUtility.html#UnityEngine_XR_ARFoundation_LoaderUtility_Deinitialize)\n- [`LoaderUtility.Initialize()`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.LoaderUtility.html#UnityEngine_XR_ARFoundation_LoaderUtility_Initialize)\n\nNext steps\n----------\n\n- [Quickstart for ARCore Extensions for Android](/ar/develop/unity-arf/quickstart-android)\n- [Quickstart for ARCore Extensions for iOS](/ar/develop/unity-arf/quickstart-ios)"]]