Script forgets assigned Inspector variables

Hi all, I have recently Updated my Character Controller to a more advanced one to finally rid my game of the horrid sluggish Unity provided one, I am now going through all the scripts to change the ‘stopping’ methods while paused/interacting ect.
When I pause the game all works as expected the Walking Controller is disabled, so the player cannot move, also the Camera Controller also gets disabled as expected this stops the camera moving around while the mouse is moving while paused.
Though the moment I try to click resume, it has forgotten what the ‘aWC’ variable was, so it attempts to get the component from the Player (the object this script is attached to) both the ‘Player’ and ‘aWC’ of which are Set as '[SerializeField]'s as can be seen in the screenshot below, the Inspecter still seems to be holding the variables, but is unable to reference them what so ever.



178742-screenshot-81.png


My code for handling the the Resume Function is: (the reasoning for all the null checks is becuase it kept failing)


public void onResume()
    {
        if(aWC != null)
        {
            aWC.enabled = true;
        }
        else
        {
            aWC = plr.GetComponent<AdvancedWalkerController>(); //ERROR  - 'plr' not assigned.
            aWC.enabled = true;
        }

        if(camCon != null)
        {
            camCon.enabled = true;
        }
        else
        {
            camCon = chr.GetComponent<CameraController>();
            camCon.enabled = true;
        }

        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
        pausedCanvas.SetActive(false);
        isPaused = false;
    }

I have also attempted to try the code as such:


if(aWC != null)
        {
            aWC.enabled = true;
        }
        else
        {
            if(plr != null)
            {
                aWC = plr.GetComponent<AdvancedWalkerController>();
                aWC.enabled = true;
            }
            else
            {
                plr = gameObject;
                aWC = plr.GetComponent<AdvancedWalkerController>();
                aWC.enabled = true; //ERROR PRINTOUT RETURNS HERE 'NullReferenceException'
            }
            
        }

with the problem then trurning into a viscious cycle and then forgetting the ‘aWC’ script Right after it has just re-assigned it. Could it be because I am disabling/enabling the ‘aWC’ and ‘CamCon’ Scripts? As this was the way I did it with the Unity Character, it never forgot who the FPC was nor the Player.


Any leads in the right direction would be greatly appreciated! Thank you and Kind Regards!

Why not do that?
Remove the plr variable and just put GetComponent<>() @FuryFight3r

 public void onResume()
     {
         if(aWC != null)
         {
             aWC.enabled = true;
         }
         else
         {
             aWC = GetComponent<AdvancedWalkerController>();
             aWC.enabled = true;
         }
 
         if(camCon != null)
         {
             camCon.enabled = true;
         }
         else
         {
             camCon = chr.GetComponent<CameraController>();
             camCon.enabled = true;
         }
 
         Cursor.lockState = CursorLockMode.Locked;
         Cursor.visible = false;
         pausedCanvas.SetActive(false);
         isPaused = false;
     }

The problem was on the button itself, the onClick() event was still trying to reference the old Player Pause Script not the new one, simply a rookie mistake :stuck_out_tongue: