月別アーカイブ: 2015年3月

[Unity, PlayMaker]:DontDestroyOnLoadの不具合

PlayMaker 1.7.8.2

アクションカテゴリ「Level」のアクション「DontDestroyOnLoad」で指定したGameObjectがシーンロード時に消えてしまいます。

DontDestroyOnLoadアクションのソースを見てみると…

// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using System.Collections;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
	[ActionCategory(ActionCategory.Level)]
	[Tooltip("Makes the Game Object not be destroyed automatically when loading a new scene.")]
	public class DontDestroyOnLoad : FsmStateAction
	{
		[RequiredField]
        [Tooltip("GameObject to mark as DontDestroyOnLoad.")]
		public FsmOwnerDefault gameObject;

		public override void Reset()
		{
			gameObject = null;
		}

		public override void OnEnter()
		{
			// Have to get the root, since the game object will be destroyed if any of its parents are destroyed.
			
			Object.DontDestroyOnLoad(Owner.transform.root.gameObject);

			Finish();
		}
	}
}

せっかく引数で指定したgameObjectが指定されていません。
代わりにこのアクションを実行しているFSMを持つGameObjectがDontDestroyOnLoadになっているようです。

25行目を以下のように変更します。

			if (gameObject != null) Object.DontDestroyOnLoad(gameObject.GameObject.Value);

[Unity]:Unity5対応でハマった点

Unity4.5.5で作成した「あ〜ちゃ〜の大冒険」をUnity5対応する時にハマった点。

Unityバージョン4.5.5f1 -> 5.0.0p2

・シーン全体が暗くなった
アンビエントライトのせい。
メニュー「Window」-「Lighting」を開き調整する。

Unity5-lighting

・NavMeshAgentの挙動がおかしい
具体的には、あ〜ちゃ〜が一度立ち止まると、その後、移動しなくなる。
従来はNavMeshAgent.Stop()後にSetDestination()で座標を設定すると動いていたのだが、Resume()を呼び出す必要がある。