Full authority transfer issue

Hi,

I’m trying to transfer networked Mine full authority to Monsters spawning player, so it would explode when Monster steps on it

  • All works fine when manually transferring authority in play mode hierarchy inspector
  • Could you, please, help me to find issue in code so it would transfer authority before exploding?

Thanks in advance!

Code that I added into Towers (Mine is considered as Tower) script

using Coherence.Toolkit;
using Coherence;

	public class MineAuthorityTransfer : MonoBehaviour
	{
		public UnitTower unitTower;
		public CoherenceSync sync;

		private void Awake()
		{
			if (sync == null)
				sync = GetComponent<CoherenceSync>();
			if (sync != null)
				sync.OnAuthorityRequest.AddListener(OnAuthorityRequest);
		}

		private void OnAuthorityRequest(AuthorityRequest request, CoherenceSync sync)
		{
			// Only allow full authority to be transferred
			request.Respond(request.AuthorityType == AuthorityType.Full);
		}

		public void TryDetonateIfMonsterInRange()
		{
			if (sync == null)
				return;
			bool hasFull = false;
			var prop = sync.GetType().GetProperty("HasFullAuthority");
			if (prop != null)
				hasFull = (bool)prop.GetValue(sync);
			else
				hasFull = sync.HasStateAuthority && sync.HasInputAuthority;

			if (!hasFull)
			{
				sync.RequestAuthority(AuthorityType.Full);
				return; // Wait for authority before detonating
			}

			// --- The following code should only run after authority is granted ---
			if (unitTower == null) return;

			if (unitTower.IsMine() && unitTower.cooldownMine <= 0)
			{
				List<Unit> tgtList = SpawnManager.GetUnitsWithinRange(unitTower, TowerManager.GetGridSize() * .25f, unitTower.GetTargetGroup());
				if (tgtList.Count > 0)
				{
					unitTower.FireMiscEffect(unitTower.shootEffObj_Mine);
					tgtList = SpawnManager.GetUnitsWithinRange(unitTower, unitTower.GetAOERange_Mine(), unitTower.GetTargetGroup());
					for (int i = 0; i < tgtList.Count; i++)
						tgtList[i].ApplyAttack(new AttackInfo(unitTower, tgtList[i], 2));

					unitTower.cooldownMine = unitTower.GetCooldown_Mine();
					if (unitTower.destroyOnTrigger)
					{
						unitTower.cooldownMine = 999;
						unitTower.Destroyed(true, false);
					}
				}
				else unitTower.cooldownMine = 0.1f;
			}
		}
	}

You don’t necessarily need to transfer authority - just send a command that the event happened and that he mine should explode: Messaging with Commands | coherence Documentation