- Home /
Editor Works, Build Not
In my game, I have public GameObject prefabs and in a script I change their sprites. It works perfectly in editor but it fails when I build it. I checked output_log file and everything seems fine. I debugged names of sprites and prefabs, they are not null and have correct values. How can something which works fine in Editor doesn't work when I build it?
Unfortunately I couldn't fixed it so I tried different methods to change sprites.
This can have multiple reasons. One reason is that preprocesser directives (something like #if UNITY_EDITOR, UNITY_ANDROID etc.). are in the code. Another reason might be unsafe code (like imported native DLL) which won't run on a Android/IOS build. But without seeing your code I just can guess.
I tried it on a new project without importing anything. I think its a Unity bug.
@L$$anonymous$$84This is my code :
public Sprite[] sprites;
public Button button1;
public Text price1;
public Image lockedPrice1;
public Image characterImage1;
public bool isUnlocked1;
public bool isChosen1;
public void OneHundred()
{
t.text = coinCounter.ToString();
if (coinCounter >= 100 && isUnlocked1 == false)
{
int coinTotal = coinCounter - 100;
PlayerPrefs.SetInt("Coin", coinTotal);
price1.gameObject.SetActive(false);
lockedPrice1.gameObject.SetActive(false);
characterImage1.gameObject.SetActive(true);
isUnlocked1 = true;
PlayerPrefs.SetInt("Unlocked1", 1);
PlayerPrefs.SetInt("Chosen1", 0);
}
else if ( isUnlocked1 == true && isChosen1 == false)
{
ball.GetComponent<SpriteRenderer>().sprite = sprites[1];
Scene$$anonymous$$anager.LoadScene("$$anonymous$$ain $$anonymous$$enu", LoadScene$$anonymous$$ode.Single);
isChosen1 = true;
PlayerPrefs.SetInt("Chosen1", 1);
PlayerPrefs.SetInt("Unlocked1", 1);
}
else if(isChosen1==true)
{
Scene$$anonymous$$anager.LoadScene("$$anonymous$$ain $$anonymous$$enu", LoadScene$$anonymous$$ode.Single);
ball.GetComponent<SpriteRenderer>().sprite = sprites[1];
}
t2.text = PlayerPrefs.GetInt("Coin", 0).ToString();
t.gameObject.SetActive(false);
t2.gameObject.SetActive(true);
}
$$anonymous$$y point is when the player wants to buy another character i want the freshly bought one(sprite) to replace the deffault sprite.On editor it works great but on Android or IOS it just doesn't change. Thanks in advance ;)
It is difficult to test it without actual project. In last "else if" block, you are loading scene then changing sprite of ball. $$anonymous$$aybe it works well on editor but on Android it loads it and can't change the sprite after. I suggest you to swap those lines, first change sprite then load the scene.