- Home /
List.add() causing issues on android build
Hello. So i have recently started having errors on the android build that don't appear when testing in the inspector. The setup i have is a button and when it is pressed i want it to add the name of a sprite to a list. I also have another button which removes the name of a sprite from the list. Both of these functions work in the inspector and no errors come up in the console related to it. However, when ran on my phone when built to android, neither of the functions allows the value to be added to the list and wont allow me to interact with the list.
What should happen when button is pressed (What happens in the inspector when the button is pushed):
Starting Code to do with list
public List<string> FavouriteBoardGames;
private void Start()
{
ScenceName = SceneManager.GetActiveScene().name;
if (ScenceName == "Libary")
{
FavouriteBoardGames = new List<string>();
LoadFavBoardGames();
}
}
The code for adding to the List
public void AddToFavourite()
{
string name = image.GetComponent<Image>().sprite.name;
Favoruite.SetActive(false);
UnFavourite.SetActive(true);
FavouriteBoardGames.Add(name);
SaveFavourites();
}
The code for removing from the List
public void RemoveToFavourite()
{
string name = image.GetComponent<Image>().sprite.name;
Favoruite.SetActive(true);
UnFavourite.SetActive(false);
FavouriteBoardGames.Remove(name);
SaveFavourites();
}
I've moved the order of the code around to test on the android build what it crashes on. On the build, it runs up to FavouriteBoardGames.Add(name); doesn't do that and doesn't carry on to save the information. The name of the board game isn't null and returns the correct value on the android build (i put a UI text on the screen and changed the text to be the name of the sprite name and it worked).
Are you sure that your scene name is library on android? Which is checked here.
if (ScenceName == "Libary")
{
FavouriteBoardGames = new List<string>();
LoadFavBoardGames();
}
That is the name of the scene (in my bad spelling) which matches up with the check of the scene name. I also put a Text UI element into the secene and put this in the if statment:
if (ScenceName == "Libary")
{
FavouriteBoardGames = new List<string>();
LoadFavBoardGames();
debug.text = "Loaded";
}
and the text changed when the correct scene was loaded (Just to be on the safe side lol)
Answer by filerjosh · May 23, 2018 at 01:49 PM
Anyone Got any idea whats wrong?
As far as I think List.add() is not causing any issue because it is so much basic functionality we use every day. It is some other issue may be complete scripts might help. $$anonymous$$oreover one mistake could be not setting up correct execution order. See this for more info.
Your answer
