前回のネタと代わって、ちょっと備忘録。Unityには原則的にグローバル変数相当のものがないです。基本的にシーン切替えのたびにGameObjectを全部リリースしてしまう方針になっています。ある程度まとめてヒープをごっそり片付けてしまうルールです。断片化やリーク対策には適切。 なるほど確かに精神衛生的…C#などがいくら「ガベージコレクションされるインスタンス型の経由を前提にしてるから、そこは…」と言っても、リアルタイムゲームにとってヒープ領域の断片化は常に恐ろしいものです。もしいつだって高速にアクセスできる本当に無限のレジスタがあれば、何も考えずにマシンガンの弾全てを一つ一つ無圧縮サウンド付きのオブジェクトに出来て、コーディングも今よりずっと気楽なものになると思うのですが、多分、永遠に記憶領域は足らないものなのでしょう。 さてUnityでゲーム用のグローバル変数的な何かを作るとしたら、それは