微型調查員走過程

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

本指南向您展示如何使用微型調試器來找到體驗中的問題方面,並識別根源。下載體驗, 從檔案中開啟 在工作室,然後繼續。


識別問題

  1. 在 Studio 中開啟體驗後,開始使用 F5播放 按鈕進行測試。

  2. 幀率感覺不錯,但與體驗的規模和範圍相當不匹配。導航到 視圖 標籤,然後在 統計 下按一下總結

    Debug stats summary showing 45 FPS.

    請注意,幀率低於每秒 60 個幀 (FPS)。

  3. 按下 Ctrl Alt F6 ( F6 ) 開啟微型調試器。

    The MicroProfiler after opening it.

    請注意,框架時間是 一致 —條形狀大約相同高度 —所以任何造成低幀率的原因都會運行每一個幀,而不是偶爾運行並導致幀時間波動。

  4. 按下 Ctrl P ( P ) 暫停微型調試器。使用快捷鍵暫停開啟詳細模式

  5. 按一下並拖曳以移動圖表。注意工作者線程中的一個特定任務似乎使用了大量的處理時間,比主執行緒多。將鼠標懸停在 RunService.Stepped 上,注意成像所需的時間。

    Detailed mode with long labels for processes.
  6. 時間線中的堆疊條指示代碼的階層,因此繼續徘徊在較低和較低層級上以嘗試識別問題。

    On-hover details for various processes, with LocalScript highlighted. On-hover details for various processes, with Raycast highlighted.

    注意 LocalScript 標籤,該標籤表示腳指令碼名稱,以及 Raycast 標籤,該標籤表示問題可能與射線投射有關。

創建故障排除標籤

現在微型調試器提供了起點,您可以解決問題的代碼。

  1. 停止播放測試並過濾 Explorer 窗口以 localscript 尋找文件。

    A view of filtering in the Explorer window.

    搜尋 raycast 表示這段代碼可能是體驗表現糟履約的原因:


    local RAYS_PER_SECOND = 1500
    local function onStepped()
    for _ = 1, RAYS_PER_SECOND do
    local startPosition = getRandomPosition()
    local endPosition = getRandomPosition()
    local direction = endPosition - startPosition
    Workspace:Raycast(
    startPosition,
    endPosition
    )
    end
    end
    RunService.Stepped:Connect(onStepped)

    特別是,你可以看到代碼每秒鐘在隨機方向投射 1,500 光束。

  2. 要驗證這部分代碼導致渲染延遲,請用 debug.profilebegin()debug.profileend() 包裝函數的內容:


    local function onStepped()
    debug.profilebegin("Raycast Spam")
    for _ = 1, RAYS_PER_SECOND do
    local startPosition = getRandomPosition()
    local endPosition = getRandomPosition()
    local direction = endPosition - startPosition
    Workspace:Raycast(
    startPosition,
    endPosition
    )
    end
    debug.profileend()
    end

確認並修復問題

  1. 開始測試體驗,然後再次開啟微型調試器。

  2. 注意微型調試器現在顯示了自定義標籤,表示這個功能確實是根本原因。

    MicroProfiler detailed view with 'Raycast Spam' visible.
  3. 停止播放測試。

  4. 刪除或評論 onStepped() 功能和 RunService.Stepped:Connect(onStepped) 連接。

  5. 再次開始測試體驗,並再次檢查調試統計摘要。

    Debug stats summary showing 60 FPS.

    注意微調器圖上框架速率和對應的框架時間的巨大改善。