15
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?

UdonSharpは非常に便利ですが、
知らないとハマる罠 がいくつも存在します。

本記事では実際によくあるポイントをまとめます。


null参照が分かりにくい

public Animator anim;
  • Inspectorで設定し忘れる
  • 実行時エラーが分かりにくい

対策

  • 必ずInspectorを確認
  • Start()でnullチェック
if (anim == null) Debug.LogError("Animator not set");

配列サイズを後から変えられない

public int[] values;
  • 実行時に new できない
  • サイズ変更不可

対策

  • Inspectorで固定サイズ
  • 使用しない要素は無視

List が使えない

List<int> list; // 使えない

Udonでは Listは非対応 です。

対策

  • 配列を使う
  • index管理を自前で行う

string操作は重い

  • 文字列連結は高コスト
  • Updateで使うと危険

対策

  • Debug用途以外で多用しない
  • 状態管理はintやboolで

Network同期の勘違い

  • 値を変えただけでは同期されない
  • RequestSerialization() が必要
state++;
RequestSerialization();

SendCustomEventの多重呼び出し

  • 無限ループになりやすい
  • イベント地獄になる

対策

  • フラグで制御
  • 状態遷移を明確に

デバッグが辛い

  • ブレークポイント不可
  • ログ頼り

コツ

  • 状態番号をログ出力
  • Debug.Logは最低限

よくある勘違いまとめ

勘違い 実際
C#なら何でも書ける 制限あり
同期は自動 手動
Updateは普通 重い
Listが使える 使えない

まとめ

  • UdonSharpは「制限付きC#」
  • 制限を理解すると一気に楽になる
  • 設計力が重要
15
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
15
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?