After Android Install SetActive Issues
Hi guys,
I'm having an issue with a game I'm building for Android Mobile. The text that displays on each of my internal screens uses the SetActive(false) to turn off and the SetActive(true) to turn on various elements as the player moves from the homepage to the game or through levels etc...
The issue only on the phone once I've installed the game to a mobile, on the homepage you can see all text and buttons from all screens at once instead of just the homepage text and buttons.
Once you click play the game runs all of the level screens and play screens correctly and after the game over screen if you chose the Replay button it returns to the homepage with the correct text and buttons showing.
I've tried many builds and can't work out why it's showing everything from that homepage on first run, ONLY once installed to mobile and works from the editor correctly.
One other issue that is occurring with may relate is that only on the mobile none of the text of the gui text showing scores etc.. are being updated as the game runs. They are always 0 however at the end of each level the score and bonuses are shown correctly.
If anyone can help with this issue I'd really appreciate it.
PS: It seems to show the same thing as you can see in the Game screen however if I disable the other screen objects on compile it shows correctly but then you can't click through to play the game.
Here is an image of what it is doing on the mobile when you first run the game.
Do you have any redundant scene in build setting (Scenes In Build), if not, Put some code!
Answer by Delforce · May 25, 2016 at 01:48 AM
Hi MJMC,
Thanks for your reply. No I don't have any redundant scene in build setting, I only have the one called prototype. In terms of code I'll try to post the most relevant code as the Game Manager script is quite large.
On awake the game calls SetupGameObjects and used to call StartScreen which I've moved into the Start method however it didn't make any difference.
/// <summary>
/// Awake: Use this instead of the Start method as it's called first.
/// </summary>
void Awake()
{
currentLevel = 0;
gameScore = 0;
SetupGameObjects();
}
void Start()
{
StartScreen();
}
void SetupGameObjects()
{
weazelManager = GameObject.Find("Game Manager").GetComponent<WeazelManager>() as WeazelManager;
TimerText = GameObject.Find("TimerText").GetComponent<Text>();
Timer = GameObject.Find("Timer").GetComponent<Text>();
EscapedWeazels = GameObject.Find("EscapedScore").GetComponent<Text>();
WackedWeazels = GameObject.Find("WackedScore").GetComponent<Text>();
LevelGameText = GameObject.Find("Level").GetComponent<Text>();
GameScore = GameObject.Find("Score").GetComponent<Text>();
LevelImage = GameObject.Find("LevelImage");
LevelPage = GameObject.Find("LevelPage");
LevelText = GameObject.Find("LevelText").GetComponent<Text>();
HomePage = GameObject.Find("HomePage");
GameOverPage = GameObject.Find("GameOverPage");
SettingsPage = GameObject.Find("SettingsPage");
// Bush Levels
Bush3Level_1 = GameObject.Find("Bush3Level1");
Bush3_2Level_1 = GameObject.Find("Bush3_2Level1");
Bush6Level_3 = GameObject.Find("Bush6Level3");
Bush3Level_5 = GameObject.Find("Bush3Level5");
Bush3_2Level_5 = GameObject.Find("Bush3_2Level5");
Bush8Level_10 = GameObject.Find("Bush8Level10");
Bush7Level_15 = GameObject.Find("Bush7Level15");
Bush7_2Level_15 = GameObject.Find("Bush7_2Level15");
// Level Popup
LevelFinishedPopup = GameObject.Find("LevelFinishedPopup");
ScoreInLevelText = GameObject.Find("ScoreInLevelText").GetComponent<Text>();
BonusesInLevelText = GameObject.Find("BonusesInLevelText").GetComponent<Text>();
LevelWackedWeazelsText = GameObject.Find("LevelWackedWeazelsText").GetComponent<Text>();
LevelEscapedWeazelsText = GameObject.Find("LevelEscapedWeazelsText").GetComponent<Text>();
LevelBonusAddScoreText = GameObject.Find("LevelBonusAddScoreText").GetComponent<Text>();
ScoreInLevel = 0;
BonusesInLevel = 0;
LevelWackedWeazels = 0;
LevelEscapedWeazels = 0;
LevelBonusAddScore = 0;
// Lives
Hammer1 = GameObject.Find("Hammer1");
Hammer2 = GameObject.Find("Hammer2");
Hammer3 = GameObject.Find("Hammer3");
// Screen Popups
LostLifePopup = GameObject.Find("LostLifePopup");
LostLife = GameObject.Find("LostLife").GetComponent<Text>();
LivesLeft = GameObject.Find("LivesLeft").GetComponent<Text>();
// High Scores
HighScore1 = GameObject.Find("HighScore1").GetComponent<Text>();
HighScore2 = GameObject.Find("HighScore2").GetComponent<Text>();
HighScore3 = GameObject.Find("HighScore3").GetComponent<Text>();
HighScore4 = GameObject.Find("HighScore4").GetComponent<Text>();
HighScore5 = GameObject.Find("HighScore5").GetComponent<Text>();
HighScore6 = GameObject.Find("HighScore6").GetComponent<Text>();
HighScore7 = GameObject.Find("HighScore7").GetComponent<Text>();
HighScore8 = GameObject.Find("HighScore8").GetComponent<Text>();
HighScore9 = GameObject.Find("HighScore9").GetComponent<Text>();
HighScore10 = GameObject.Find("HighScore10").GetComponent<Text>();
PlayerName = GameObject.Find("PlayerName").GetComponent<InputField>() as InputField;
MusicVolume = GameObject.Find("MusicVolume").GetComponent<Slider>() as Slider;
SoundVolume = GameObject.Find("SoundVolume").GetComponent<Slider>() as Slider;
TimerText.text = string.Empty;
Timer.text = string.Empty;
// Load user preferences to start.
user = new UserPreferencesForSaving();
RefreshPrefsFromFile();
}
/// <summary>
/// StartScreen: Display Main Weazel Wacker Title Screen
/// </summary>
public void StartScreen()
{
// Reset game score.
gameScore = 0;
levelSetup = true;
LevelImage.SetActive(true);
ChangeActiveGuiPage(DisplayPage.HomePage);
if (user.CurrentPlayer != string.Empty && PlayerName.text == string.Empty)
{
PlayerName.text = user.CurrentPlayer;
}
}
private void ChangeActiveGuiPage(DisplayPage pageToChange)
{
LevelImage.SetActive(true);
HomePage.SetActive(false);
SettingsPage.SetActive(false);
LevelPage.SetActive(false);
LostLifePopup.SetActive(false);
LevelFinishedPopup.SetActive(false);
GameOverPage.SetActive(false);
switch (pageToChange)
{
case DisplayPage.HomePage:
CurrentState = GameState.HomePage;
HomePage.SetActive(true);
break;
case DisplayPage.SettingsPage:
CurrentState = GameState.Settings;
SettingsPage.SetActive(true);
break;
case DisplayPage.LevelChangePage:
CurrentState = GameState.Intermission;
LevelPage.SetActive(true);
break;
case DisplayPage.GameOverPage:
CurrentState = GameState.GameOver;
GameOverPage.SetActive(true);
break;
}
}
If you look at the ChangeActiveGuiPage this is the one that should be in place when the game first starts up. As in my original post it works okay when clicking replay button which resides on the Game Over page however when the game first runs on Mobile phone it intermingles all of the text from all of the screens into the one screen first time.
When the replay button on the Game Over screen is clicked the system is calling the same GameManager.StartScreen method as is called when the game Starts which isn't making sense to me. I'm wondering whether I need to trigger an event on the game start to make the system think someone has pressed the replay just to start the game properly but this seems like a hack to me.
@MJMC Cheers
From performance issue it is better to use public variables ins$$anonymous$$d of too much GameObject.Find().
How many scenes do you have? If it is more than 1 scene, maybe you need to use some static variables whose lifetime extends across the entire run of the program.
Also put each of your pages in a new scene which make it easy to debugging. Then call them by Scene$$anonymous$$anager.LoadScene(scene.name);
Thanks for your help $$anonymous$$J$$anonymous$$C, putting each of the screens into their own scene resolved the issue went I put it onto the mobile. It also solved another issue where the text for the score wasn't updating and was just zero for the entire game.
Cheers
You're welcome, if it was helpful vote up the answer :)
Thanks $$anonymous$$J$$anonymous$$C,
I only have 1 scene and all of the screens work by the game manager which makes them appear or disappear. I guess if I work on the basis of having multiple scenes one for each of the pages then it may fix the issue with the mobile as it will just run the 1st scene. That might work I'll accept this if it works once I try that out.
Thanks for your help with this.
Cheers
Your answer

Follow this Question
Related Questions
Campaign installs on Android not tracked in Facebook Analytics for Apps 0 Answers
Cannot Change "Install Location" Under Player Settings for Android Application 1 Answer
Unable to detect Android sdk in selected folder?,Invalid android SDK directory with android studio? 1 Answer
Application not installed 0 Answers
does direct SQL connection with Unity work in Android? 0 Answers