- Home /
Script disables for no reason
Hi, I was debugging my game, testing if my 2D Character was moving properly. I go to my pause menu and also test when the game resets, and on load the character doesn't move anymore. I'm think it was a just bug in the script, so I had to double check again and now the character no longer moves.
I checked the components of the Character I was working on and it turned out that the Player Script randomly disables and I have to manually turn it back on. The problem I'm facing is that it has been constantly turning off outside of play mode when it's not given the order to do so. Is this a bug or something?
I have never seen a script disable itself, unless there was code somewhere telling it to.
I would double check all your code, and see if you can track down the culprit. Quickest way would be to use the find feature of your IDE, and look for all references to the script that is getting disabled.
I manage to find the problem, it came from the Pause $$anonymous$$enu where it disables Player $$anonymous$$ovement with in the menu and I had to trigger it back ".enabled = true" when resetting the level.
Glad you were able to get it straightened out.
Answer by Lafikobra · Dec 21, 2019 at 07:12 PM
Yeah, i had this too and it was a bug. Try adding a new script to the player, and add this lines to it:
PlayerControllerScriptName script;
private void Start()
{
script = GetComponent<PlayerControllerScriptName>();
script.enabled = true;
}