Hello, today I was trying to centralize my code and I have run into an interesting problem with even more fascinating solution. So the script which is a grandchild of the script that it is finding returns error:
NullReferenceException: Object reference not set to an instance of an object
is while trying to debug it I wrote an if statement that checks if the object is not null at the start and the problem was fixed . Here is how the code looks like after deleting the Debug.Log()
private PlayerControler pControlerSelect;
void Start () {
pControlerSelect = FindObjectOfType<PlayerControler>();
if (pControlerSelect != null)
{
}
WeaponSelect();
}
also the error fires from the line that is in method WeaponSelect() and changing the statement to check if the object is null returns the error