class ApplyShaderOnObjectEffector extends Effector
{
	private var m_applicationTargetName : CName;
	private var m_applicationTarget : weak< GameObject >;
	private var m_effects : array< EffectInstance >;
	private var m_overrideMaterialName : CName;
	private var m_overrideMaterialTag : CName;
	private var m_overrideMaterialClearOnDetach : Bool;
	private var m_effectInstance : EffectInstance;
	private var m_owner : weak< GameObject >;
	private var m_ownerEffect : EffectInstance;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_applicationTargetName = TweakDBInterface.GetCName( record + T".applicationTarget", '' );
		m_overrideMaterialName = TweakDBInterface.GetCName( record + T".overrideMaterialName", '' );
		m_overrideMaterialTag = TweakDBInterface.GetCName( record + T".overrideMaterialTag", '' );
		m_overrideMaterialClearOnDetach = TweakDBInterface.GetBool( record + T".overrideMaterialClearOnDetach", false );
	}

	protected override function ActionOn( owner : GameObject )
	{
		m_owner = owner;
		GetApplicationTarget( m_owner, m_applicationTargetName, m_applicationTarget );
		m_effectInstance = GameInstance.GetGameEffectSystem( m_owner.GetGame() ).CreateEffectStatic( m_overrideMaterialName, m_overrideMaterialTag, m_owner );
		if( ( m_effectInstance && IsNameValid( m_overrideMaterialName ) ) && m_applicationTarget )
		{
			EffectData.SetBool( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.enable, true );
			EffectData.SetBool( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.clearMaterialOverlayOnDetach, m_overrideMaterialClearOnDetach );
			EffectData.SetEntity( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.entity, m_applicationTarget );
			m_effectInstance.Run();
		}
	}

	protected override function ActionOff( owner : GameObject )
	{
		m_effectInstance = GameInstance.GetGameEffectSystem( m_owner.GetGame() ).CreateEffectStatic( m_overrideMaterialName, m_overrideMaterialTag, m_owner );
		if( ( m_effectInstance && IsNameValid( m_overrideMaterialName ) ) && m_applicationTarget )
		{
			EffectData.SetBool( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.enable, false );
			EffectData.SetEntity( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.entity, m_applicationTarget );
			m_effectInstance.Run();
		}
	}

	protected override function Uninitialize( game : GameInstance )
	{
		m_effectInstance = GameInstance.GetGameEffectSystem( game ).CreateEffectStatic( m_overrideMaterialName, m_overrideMaterialTag, m_owner );
		if( m_effectInstance && IsNameValid( m_overrideMaterialName ) )
		{
			EffectData.SetBool( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.enable, false );
			EffectData.SetEntity( m_effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.entity, m_applicationTarget );
			m_effectInstance.Run();
		}
	}

}

