'Game works fine in editor, not in build
I am working on a game and i have a script to save the stats for characters. The same script is used for hero and for the enemies.
There are actually 2 scripts. 1st script is for game settings which makes sure that which player is to be set visible and which enemy to set visible. That script has variables like
[Header("Players")]
public GameObject LocalPlayer;
public GameObject Enemy;
Now in my 2nd script with name User_stats, i want to put target for hero = enemy and vice versa. What i am doing in my 2nd script is that i calling my 1st script (FKManage) in it by doing following code
private FKManage FKManage; Then in my void start, I am using a method named SetTarget(); which is defining these two arrays and telling them that the objects with tag player need to have Target = Enemy from the FKManage script and vice versa
GameObject[] protagonistOpponent = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject obst in protagonistOpponent)
obst.GetComponent<User_Stats>().Target = FKManage.Enemy.transform;
GameObject[] AntagonistOpponent = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject obst in AntagonistOpponent)
obst.GetComponent<User_Stats>().Target = FKManage.LocalPlayer.transform;
And it works fine but only in Unity editor. As soon as i build the game for Android and run it under Android, my characters don't do anything (because target is not set).
I want to know why my build is not working right as it is working in editor? Where am i making the mistake? On building the game, this is the error i get in my android logcat.
Solution 1:[1]
So i have fixed the issue.
What i have done is i have changed the script execution order, a really simple fix and works like a charm. Read about how to change script execution here
Thank you everyone for helping me out especially @BugFinder and @AykutKaraca
Solution 2:[2]
For any one who still doesn't solved the problem, check if you have code like Debug.Assert()
. Such debug code (methods like print() excluded) will be deleted in the build version.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rameez Safdar |
Solution 2 | Gytobp |