namespace BP
{
	//Serializable Actor
	class SActor
	{
		int instanceID;
		kActor @actor;
		//------------------------------------------------------------------------------------------------------------------------
		SActor()
		{
			instanceID = 0;
			@actor = null;
		}
		//------------------------------------------------------------------------------------------------------------------------
		SActor(kActor @actor)
		{
			SetActor(@actor);
		}
		//------------------------------------------------------------------------------------------------------------------------
		bool opEquals(const SActor &in other)
		{
			return @actor == @other.actor;
		}
		//------------------------------------------------------------------------------------------------------------------------
		SActor@ opAssign(const SActor &in other)
		{
			instanceID = other.instanceID;
			@actor = @other.actor;
			
			return this;
		}
		//------------------------------------------------------------------------------------------------------------------------
		#ifdef BP_DEBUG
		kStr ToString()
		{
			kStr s = "instanceID: " + instanceID + " actor: ";
			if (@actor == null)
			{
				s += "Null";
			}
			else
			{
				s += "" + actor.Type();
			}
			return s;
		}
		#endif
		//------------------------------------------------------------------------------------------------------------------------
		bool Exists()
		{
			return @actor != null && !actor.IsStale() && instanceID != 0;
		}
		//------------------------------------------------------------------------------------------------------------------------
		void SetActor(kActor @actor)
		{
			@this.actor = @actor;
			instanceID = BP::Trigger::InstanceID(@actor);
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Clear()
		{
			instanceID = 0;
			@actor = null;
		}
		//------------------------------------------------------------------------------------------------------------------------
		void Serialize(kDict& in dict, const kStr& in key)
		{
			dict.Add(key, "" + instanceID);
		}
		//------------------------------------------------------------------------------------------------------------------------
		bool Deserialize(kDict& in dict, const kStr& in key)
		{
			return dict.GetInt(key, instanceID);
		}
		//------------------------------------------------------------------------------------------------------------------------
		void SetDeserializedActor()
		{
			if (instanceID != 0)
			{
				kActorIterator iter;
				kActor@ iActor;
				while ((@iActor = iter.GetNext()) !is null)
				{
					int instID = BP::Trigger::InstanceID(@iActor);
					if (instID == instanceID)
					{
						@actor = @iActor;
						return;
					}
				}
				DebugError("Did not find actor with instanceID " + instanceID);
			}
			@actor = null;
		}
		//------------------------------------------------------------------------------------------------------------------------
	};
}
