- Home /
Script works in the editor but not in builds
I have created a script that removes gaps between moving platforms on my 2D sidescroller game by checking for another platform infront of the platform with the script and then aligning itself to this platform.
The script works perfectly as planned in the unity editor and on PC standalone, but when I put the game onto my android phone, there are gaps and it runs as if the script doesn't even exist.
There are also no errors whatsoever on PC or android
Here is my script:
using UnityEngine;
using System.Collections;
public class CheckPos : MonoBehaviour {
public Transform _alignTo = null;
public bool _align = false;
Transform myTransform;
void Start ()
{
myTransform = transform;
}
void Update()
{
myTransform.position = transform.parent.position;
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Environment" && _align == true){
_alignTo = other.transform;
Align();
}
}
void OnTriggerExit ()
{
_alignTo = null;
}
public void Align()
{
//yield return new WaitForSeconds(0.1f);
myTransform.parent.position = _alignTo.transform.position + new Vector3(1f, 0f, 0f);
}
}
UPDATE:
I have built a standalone PC version of the game with better debugging. It seems I have the same problem as with android on pc standalone as well.
Unfortunately the errors are fairly vague so I can't pinpoint the problem... any ideas?
How you can say, this script is causing problem?? Debug your game while running on android. Hope for the best
I have done debugging on android. there are no errors or anything returned, it is just as if he script isn't there in the android version
Nothing wrong with your script, so there must be something specific going on elsewhere. Improve on your debugging ;) Just checking if errors are returned isn't the whole thing. To make things simple you can start by adding Debug.Log statements to anything you suspect isn't working, then build with the development build option on. This should at least give you information about which methods are being called. Also test your build settings. .NET 2.0 and stripping disabled, slow and safe script execution if supported.
If it seems like it is not there then maybe it is not there? $$anonymous$$g. read about "magic folders"
I have updated the question after trying with better debugging
I now get the error "UnityException: GameObject has undefined tag!"
Answer by Xarbrough · Apr 06, 2015 at 02:56 PM
GameObject has undefined tag, means that you've previously assigned a tag to an object, you are now querying that tag, but it was deleted from the Tags list in Project Settings > Tags. If it's still there, check the spelling or maybe recreate it to see if that fixes it. All this shouldn't make any difference between platforms.
This happened to me when Unity tried to fix a project for some reason. "Fix" removed all my tags and even though they were visible in Inspector view, the tag list itself was empty. Just a heads up in case someone fixes project and experiences the same, really frustrating thing.
Answer by NullTerminated · Sep 15, 2017 at 08:18 PM
For anyone who had a similar issue:
What happened to me was that I deleted some tags I no longer needed. Then In the editor, the game worked perfectly, but in the build it did not. This is because I ignored the the Unity editor message located right at the bottom of the Tags editor saying something along the lines: if you delete them, you need to restart unity in order for the removed tags to be fully removed.
This will cause errors in your builds if you don't restart unity and fully remove tags.
Answer by ethestel · Apr 07, 2015 at 09:50 AM
try
other.gameObject.CompareTag("Environment")
instead of
other.tag == "Environment"
Hope it helps.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Android APK acts different than in Editor 1 Answer
Distribute terrain in zones 3 Answers
Initialising List array for use in a custom Editor 1 Answer
WaitForSeconds(3) on Android waits less than expected 2 Answers