Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. //All these null checks in order to make absolutely sure the null reference can not occur... And yet it does.
  2. public void SetShouldShowAgent()
  3.         {
  4.             var currentIdentity = BlackboardController.GetCurrentPlanIdentity();
  5.             var gameData = GameDataContainer.GetGameData();
  6.  
  7.             if (currentIdentity == null || gameData == null) return;
  8.             if (currentAgent == null) return;
  9.  
  10.             bool shouldShowAgent = true;
  11.  
  12.             if (!gameData.agents.Contains(currentAgent)) shouldShowAgent = false;
  13.  
  14.             if (!currentAgent.IsAvailable(currentIdentity.target)) shouldShowAgent = false;
  15.  
  16.             if (shouldShowAgent) gameData.StoreAgentMissionPlanningPosition(currentIdentity, currentAgent, (Vector2)transform.localPosition);
  17.  
  18.             if (this == null || gameObject == null) return;
  19.             gameObject.SetActive(shouldShowAgent); //<----   Exception hits here
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement