facebook twitter hatena line email

「Unity/負荷軽減/基本」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の3版が非表示)
行1: 行1:
 
==profiler確認==
 
#unityメインメニュー/window/analysis/profilerで確認
 
#playボタンを押すと動作する
 
 
==使用状況詳細確認==
 
#profilerでCPU Usageを選択
 
#左中段にある、cmbボタンを選択し、Hierarchyを選択。
 
#Liveを選択
 
#GC Allocなど確認できる。
 
 
===実行中に使用状況を確認する場合===
 
#play実行
 
#profilerでCPU Usageを選択
 
#左中段にある、cmbボタンを選択し、Hierarchyを選択。
 
#グラフのどこかをクリックして、選択
 
#PlayerLoopのところを展開していく。
 
 
参考:
 
https://light11.hatenadiary.com/entry/2019/09/19/000006
 
  
 
==対策方法==
 
==対策方法==
行26: 行6:
  
 
参考:https://squmarigames.com/2018/12/13/unity-beginner-find/
 
参考:https://squmarigames.com/2018/12/13/unity-beginner-find/
 +
 +
=== FindObjectOfTypeも重い、GameObject.FindWithTagを使う===
 +
参考:https://baba-s.hatenablog.com/entry/2014/07/09/093240
  
 
===Json.netよりJson.Utilityを使う===
 
===Json.netよりJson.Utilityを使う===
行35: 行18:
 
参考:https://xrdnk.hateblo.jp/entry/2020/03/23/210320#TryGetComponent%E3%81%A8%E3%81%AF
 
参考:https://xrdnk.hateblo.jp/entry/2020/03/23/210320#TryGetComponent%E3%81%A8%E3%81%AF
  
===LogStringToConsoleの処理==
+
===LogStringToConsoleの処理===
 
Debug.Log()はできるだけ消す。
 
Debug.Log()はできるだけ消す。
  
 
参考:https://masakami.com/archives/2019/02/04/34/
 
参考:https://masakami.com/archives/2019/02/04/34/
 +
 +
===UniRxの購読の解除を===
 +
参考:https://zenn.dev/keisuke114/scraps/6f9496752208c0

2023年8月25日 (金) 22:11時点における最新版

対策方法

GameObject.Findは重い、GameObject.FindWithTagを使う

GameObject tag = FindWithTag("Tag1");

ObjectのInspectorの上のほうにaddTagする。

参考:https://squmarigames.com/2018/12/13/unity-beginner-find/

FindObjectOfTypeも重い、GameObject.FindWithTagを使う

参考:https://baba-s.hatenablog.com/entry/2014/07/09/093240

Json.netよりJson.Utilityを使う

参考:https://yubeshicat.hatenablog.com/entry/2019/11/02/180914

GetComponentよりTryGetComponentを使う?

GetComponentをTryGetComponentにすることで、GC Allocが発生しなくなる?

参考:https://xrdnk.hateblo.jp/entry/2020/03/23/210320#TryGetComponent%E3%81%A8%E3%81%AF

LogStringToConsoleの処理

Debug.Log()はできるだけ消す。

参考:https://masakami.com/archives/2019/02/04/34/

UniRxの購読の解除を

参考:https://zenn.dev/keisuke114/scraps/6f9496752208c0