16
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VRChatワールド制作において、Udon(UdonSharp)と最適化は切り離せない要素です。
本記事では「なぜUdonが重くなるのか」「どう設計すれば軽くなるのか」を整理します。


なぜUdonが最適化に影響するのか

Udonは以下の理由でワールド負荷に直結します。

  • 毎フレーム実行される処理が多い
  • 同期処理がネットワーク負荷を生む
  • 不要なイベントが全プレイヤーに影響する

特に CPU負荷・同期トラフィック に影響します。


Update() の使いすぎ問題

よくある例

void Update()
{
    CheckDistance();
}

これは 毎フレーム全員分実行 されます。

改善案

  • Updateを使わない
  • SendCustomEventDelayedSeconds を使う
  • 必要な時だけ処理する
public void Check()
{
    CheckDistance();
    SendCustomEventDelayedSeconds(nameof(Check), 1f);
}

👉 1秒に1回で十分な処理はUpdateを使わない


ネットワーク同期は最小限に

同期変数の落とし穴

[UdonSynced] public int state;
  • 変更のたびに全員へ同期
  • 頻繁に変えるとラグの原因

ポイント

  • 同期は「状態」だけ
  • 演出・アニメーションはローカル処理
  • Ownerのみが値を変更する

Owner設計は最重要

  • 処理は基本Ownerのみ
  • 他人は「見るだけ」にする
if (!Networking.IsOwner(gameObject)) return;

これだけで 負荷とバグが激減 します。


Collider / Trigger 乱用に注意

  • OnTriggerStay は毎フレーム呼ばれる
  • 不要なColliderは削除

代替案:

  • OnTriggerEnter / Exit を使う
  • 距離判定は一定間隔で

大規模ワールドでの設計指針

  • エリアごとにUdonを分割
  • 使われていないギミックは無効化
  • オブジェクト非表示時は処理も止める
gameObject.SetActive(false);

まとめ

  • Updateは極力使わない
  • 同期は最小限
  • Owner設計を徹底
  • イベント駆動で設計する

Udon最適化 = ワールド最適化 です。

16
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?