テラシュールブログ

旧テラシュールウェアブログUnity記事。主にUnityのTipsやAR・VR、ニコニコ動画についてのメモを残します。

【Unity】コンパイルが通りエラーも表示されずゲームも実行可能なのに、処理が実行されない

少し面白い挙動に出会ったのでメモ。

 

スクリプトエラーが無いのに処理が実行されない

少し面白い挙動に出会いました。

下のようにビルドは通っておりエラーも特に無く、ゲームを再生出来るのですが、実行時に新しく記述した処理が反映されませんでした

また実行時にThe associated script can not be loaded. Please fix any compile errors and assign a valid script.(スクリプトロード出来ませんでした。コンパイルエラーを修正し、有効なスクリプトを割り当てて下さい)と表示されます。

f:id:tsubaki_t1:20161006225319j:plain

f:id:tsubaki_t1:20161006225324j:plain

 

また、The referenced script on this Behaviour is missing!The referenced script on this Behaviour (任意のGameObject) is missing!といったWarningも表示されます。
はてさて。

f:id:tsubaki_t1:20161006232318j:plain

 

コンポーネント名とクラス名が一致していなかった

よく確認すると、コンポーネント名とクラス名が不一致なだけでした。
UnityはMonobehaviourを使用する場合、クラス名とソースコード名が一致してる必要があるのですが、コンポーネント登録後にクラス名を変更したため、こんな感じになっていました。

f:id:tsubaki_t1:20161006230240j:plain

 

一応今まで通り、新しくコンポーネントを登録する際にはエラーが表示されるのですが、既に登録してあった場合は少し分かりにくい挙動です。

f:id:tsubaki_t1:20161006230542j:plain

 

Unity 5.5のユニークな挙動

そういえばUnity 5.5からか、(バグかもしれませんが)「ファイル内にファイル名と一致するMonobehaviourがあれば、該当するMonobehaviourを動かす」という挙動を行うみたいです。凄く分かりにくい。

f:id:tsubaki_t1:20161006231235j:plain

 

メモ

今回の記事を書いていて思い出したのですが、Betaにてシリアライズしたスクリプトのパラメータを安全に更新する仕組みを作ってるみたいです。

https://forum.unity3d.com/threads/script-data-upgrade.427767/

Over the course of a project, it is very common that the design of code will change, particularly with regards to persistent data. Fields will be added, removed, renamed; they will change type; they will change meaning, such as changing the units they are representing. Making these changes in the middle of a live project, where there is a substantial amount of content already using the existing data layouts, can be challenging.

The Script Data Upgrade feature provides a way to make structured, safe, on-demand changes to your stored data, so you can smoothly bring your created content along as you iterate on your data structures.

 

関連

tsubakit1.hateblo.jp

tsubakit1.hateblo.jp