At first, the game works fine crash play ad to continues playing. The next crash then reloads the game after that next crash I play ad after that I lose connection to the player Controller to enable the player to continue playing. I am making an infinite Runner I get this:
MissingReferenceException: The object of type ‘PlayerController’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
some of the ad code and I am getting the debug.log
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
if (showResult == ShowResult.Finished)
{
playerController.ResumeGame();
Debug.Log("Ad R finished");
}
else if(showResult == ShowResult.Failed)
{
gameManager.reSume = true;
Debug.Log("Ad R Failed");
}
}
what I am losing the part of the player controller and looking at the inspector it’s still there.
public void ResumeGame()
{
Debug.Log("trying to resume");
this.transform.position = new Vector3(0, 2f, transform.position.z);
resetbox.SetActive(false);
anim.Play("Warrior Idle");
gameManager.readyToReSume = true;
Debug.Log("Ready to keep going");
}
Hello. Your code does not show enough information. I guess that somewhere you destroy your PlayerController or you lose its reference, maybe restarting the scene (as your title says). Inspector cannot lie - you destroyed your PlayerController
However, it’s not the best way (rush job), but you could forced the PlayerController reference adding an IF statement is the Update section:
if (player == null)
player = GameObject.FindWithTag("Player");
May I take a look at the GameManager script, especially the ReSumeedOrRestartLevel() function ? I am pretty sure that you did something wrong here. Respectfully, your code is a little bit hard coded. In the ResumeGame function, IF and ELSEIF have the same code !!! Just a little advice ; check in all your scripts where there is a Destroy() calling. There is something wrong somewhere ++
hi ok i looked over every code i have nothing is calling Destroy() for playercontroller.
here is just ReSumeedOrRestartLevel() thanks for taking the time to help out.
public void ReSumeedOrRestartLevel()
{
generatelevel.enabled = false;
playerMove.enabled = false;
reSumeButton.SetActive(false);
if (resumed == false)
{
adButton.SetActive(true);
reStartButten.SetActive(true);
Debug.Log("Can Be ReSumeed");
}else if (resumed == true)
{
adButton.SetActive(false);
reStartButten.SetActive(true);
Debug.Log("already ReSumeed");
}
Nothing. I regret, but I cannot identify your bug. It’s really hard coded, but in the same time, it seems correct. In your inspector, you have a long message with the error (as you said, player does not exist anymore), but you have some numbers too and scripts name. It could help you to find the problem ++
ita something to do with ad script. I added hearts to use instead of watching ads and it works just fine. I change the ad script to go through game manager first and it still gives me the same thing.
The message in the inspector is clear. Somewhere in your scripts, during the process, you disable (or destroy) the PlayerController script. I guess that it happens in the RewardedAdDisplay script (maybe line 67). Sorry, but I cannot do more ++