- Home /
Why does my game only work after the second time I launch it?
I built my first game with Unity. I have tested it on an Android tablet and a Windows PC. I have the same problem on both platforms. After installing the game it never works on the initial launch, but every time after that it works smoothly without any faults. Is this a problem with Unity personal edition or should I look at my code somewhere? If it's my code, please give me any suggestion where I should start to look.
Does the error occur in editor too? Define "not working".
Thanks, for your reply. There are 5 buttons on the first scene of my game( game level, controls, ball design , quit and game instructions). When I start the game after installing it the buttons dont work(flash as set but no action / response). But every time after that they work fine, it only happens on the initial start after installing the game. The same thing happens with android on a tablet, or windows on a pc. Actually it also happens in the unity editor when i try the game. Any advice would be appreciated,
if it's reproducible in the editor it's more easy.
next step would be to reproduce the error consistently. If you know when it occurs you can check why. pressing buttons is easy enough so you should check if the code behind it is executed. If it is, where is it different? are you checking done PlayerPrefs first written on the first run? etc
Hello, I had a problem with "Build and Run" option Everytime that Unity AUTO initialized a build it wouldn't work properly
I would recommend just build
and Run the game manually yourself - NOT "Build and Run"
hope it works
Answer by ClanAlba · Dec 05, 2016 at 09:15 AM
Hi, Many thanks for the replies. It seems the problem is it's not loading the player prefs when the game runs for the first time. Obviously the first time the game runs there isn't any data to load, so how to I get round that problem. I have an void Awake script in another script but is doesnt seem to be checking this properly. Please help / advise again.
private void Awake() { instance = this; DontDestroyOnLoad (gameObject);
if (PlayerPrefs.HasKey ("CurrentSkin"))
{ // We had a previous session
currentSkinIndex = PlayerPrefs.GetInt ("CurrentSkin");
currency = PlayerPrefs.GetInt ("Currency");
skinAvailability = PlayerPrefs.GetInt ("SkinAvailability");
} else
{
Save();
}`
$$anonymous$$any thanks for all your advice. I finally sorted out the problem with the buttons and finally showing the levels. I made a separate script for the button On Click Events and moved the level script into a private void Awake to find the information on the initial start when there is no data yet. Thank you all again,
No doubt I will be on here again with future games and coding.
Have your self a very $$anonymous$$erry $$anonymous$$