Game crashes

In editor is working fine, but after i build the game files and i buy a weapon, my game just crashes, why is happen that?, in console i don’t get any error.

EDIT: When i am in Weapon Shop, Time.timeScale = 0.

WeaponShop code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using CodeStage.AntiCheat.ObscuredTypes;
using UnityEngine.SceneManagement;

public class WeaponShop : MonoBehaviour
{

    [Header("-Weapon Settings 01-")]
    public Button WeaponButton1;
    public ObscuredInt WeaponPrice1 = 5000;
    public ObscuredInt WeaponPriceInsane1 = 1500;
    public ObscuredInt LevelForWeapon1 = 5;
    public Text weaponPriceText1;
    public GameObject blockedPannel;
    public Text levelTextPermison;

    [Header("-Weapons Boolen Options-")]
    public ObscuredBool weaponPsitol = true;
    public ObscuredBool weaponAssaultRifle = false;

    SwichWeapons wp1;

    private ObscuredString InsaneSceneName = "InsaneWaveInferno";


    void Start()
    {
        WeaponButton1.interactable = false;

        weaponPsitol = true;
        weaponAssaultRifle = false;

        weaponPriceText1.text = WeaponPrice1 + "$";

        SwichWeapons changeWeapon = FindObjectOfType(typeof(SwichWeapons)) as SwichWeapons;
        changeWeapon.DefaultWeaponVoid();

        Scene currentScene = SceneManager.GetActiveScene();
        string sceneName = currentScene.name;

        if (sceneName == InsaneSceneName)
        {
            WeaponPrice1 = WeaponPriceInsane1;
        }
    }

    void Update()
    {
        if (UpgradeMenu.Money >= WeaponPrice1)
        {
            if (weaponAssaultRifle == false && weaponPsitol == true)
            {
                WeaponButton1.interactable = true;
            }
            else if (weaponAssaultRifle == true && weaponPsitol == false)
            {
                WeaponButton1.interactable = false;
            }
        }
        else
        {
            WeaponButton1.interactable = false;
        }

        if (LevelSystem.PlayerLevel < LevelForWeapon1)
        {
            blockedPannel.SetActive(true);

            levelTextPermison.text = "You don't have level " + LevelForWeapon1;

            WeaponButton1.interactable = false;
        }
        else if (LevelSystem.PlayerLevel >= LevelForWeapon1)
        {
            blockedPannel.SetActive(false);
        }



        if (weaponPsitol == true && weaponAssaultRifle == false)
        {
            SwichWeapons changeWeapon = FindObjectOfType(typeof(SwichWeapons)) as SwichWeapons;

            if (changeWeapon != null)
            {
                changeWeapon.DefaultWeaponVoid();
            }

            weaponPriceText1.text = WeaponPrice1 + "$";
        }

        if (weaponAssaultRifle == true && weaponPsitol == false)
        {
            SwichWeapons changeWeapon = FindObjectOfType(typeof(SwichWeapons)) as SwichWeapons;

            if (changeWeapon != null)
            {
                changeWeapon.weapon01Void();
            }

            weaponPriceText1.text = "Owned";
        }
    }

    public void BuyWeapon01()
    {
        if (LevelSystem.PlayerLevel >= LevelForWeapon1)
        {
            if (UpgradeMenu.Money >= WeaponPrice1)
            {
                weaponAssaultRifle = true;
                weaponPsitol = false;

                UpgradeMenu.Money -= WeaponPrice1;
            }
        }
    }
}

SwichWeapons code:

using UnityEngine;
using System.Collections;

public class SwichWeapons : MonoBehaviour
{

    public GameObject defaultWeapon;
    public GameObject weapon1;

    void Start()
    {
        defaultWeapon.SetActive(true);
        weapon1.SetActive(false);
    }

    public void DefaultWeaponVoid()
    {
        defaultWeapon.SetActive(true);
        weapon1.SetActive(false);
    }

    public void weapon01Void()
    {
        defaultWeapon.SetActive(false);
        weapon1.SetActive(true);
    }
}

Check the log files, built games create a log file (on windows/mac) or if your testing on mobile, try connecting to ADB to the device, and see what the log outputs when it crashes.

In Output_log the last output is this:

(Filename: E:/Unity 5/Proiecte/SpacePlatformer/Assets/Scripts/EnemyAI.cs Line: 85)

Setting up 1 worker threads for Enlighten.
Thread → id: 970 → priority: 1

EnemyAI Code:

using UnityEngine;
using System.Collections;
using Pathfinding;

[RequireComponent (typeof (Rigidbody2D))]
[RequireComponent (typeof (Seeker))]
public class EnemyAI : MonoBehaviour {

    // What to chase?
    public Transform target;
   
    // How many times each second we will update our path
    public float updateRate = 2f;
   
    // Caching
    private Seeker seeker;
    private Rigidbody2D rb;
   
    //The calculated path
    public Path path;
   
    //The AI's speed per second
    public float speed = 300f;
    public ForceMode2D fMode;
   
    [HideInInspector]
    public bool pathIsEnded = false;
   
    // The max distance from the AI to a waypoint for it to continue to the next waypoint
    public float nextWaypointDistance = 3;
   
    // The waypoint we are currently moving towards
    private int currentWaypoint = 0;

    private bool searchingForPlayer = false;
   
    void Start () {
        seeker = GetComponent<Seeker>();
        rb = GetComponent<Rigidbody2D>();
       
        if (target == null) {
            if (!searchingForPlayer) {
                searchingForPlayer = true;
                StartCoroutine (SearchForPlayer());
            }
            return;
        }
       
        // Start a new path to the target position, return the result to the OnPathComplete method
        seeker.StartPath (transform.position, target.position, OnPathComplete);
       
        StartCoroutine (UpdatePath ());
    }

    IEnumerator SearchForPlayer () {
        GameObject sResult =  GameObject.FindGameObjectWithTag ("Player");
        if (sResult == null) {
            yield return new WaitForSeconds (0.5f);
            StartCoroutine (SearchForPlayer ());
        } else {
            target = sResult.transform;
            searchingForPlayer = false;
            StartCoroutine (UpdatePath());
            return false;
        }
    }
   
    IEnumerator UpdatePath () {
        if (target == null) {
            if (!searchingForPlayer) {
                searchingForPlayer = true;
                StartCoroutine (SearchForPlayer());
            }
            return false;
        }
       
        // Start a new path to the target position, return the result to the OnPathComplete method
        seeker.StartPath (transform.position, target.position, OnPathComplete);
       
        yield return new WaitForSeconds ( 1f/updateRate );
        StartCoroutine (UpdatePath());
    }
   
    public void OnPathComplete (Path p) {
        Debug.Log ("We got a path. Did it have an error? " + p.error);
        if (!p.error) {
            path = p;
            currentWaypoint = 0;
        }
    }
   
    void FixedUpdate () {
        if (target == null) {
            if (!searchingForPlayer) {
                searchingForPlayer = true;
                StartCoroutine (SearchForPlayer());
            }
            return;
        }
       
        //TODO: Always look at player?
       
        if (path == null)
            return;
       
        if (currentWaypoint >= path.vectorPath.Count) {
            if (pathIsEnded)
                return;
           
            Debug.Log ("End of path reached.");
            pathIsEnded = true;
            return;
        }
        pathIsEnded = false;
   
        //Direction to the next waypoint
        Vector3 dir = ( path.vectorPath[currentWaypoint] - transform.position ).normalized;
        dir *= speed * Time.fixedDeltaTime;
       
        //Move the AI
        rb.AddForce (dir, fMode);
       
        float dist = Vector3.Distance (transform.position, path.vectorPath[currentWaypoint]);
        if (dist < nextWaypointDistance) {
            currentWaypoint++;
            return;
        }
    }
   
}

The log doesn’t necessarily end at the crash, so it is not necessarily the last line that has the required info. There should be a callstack somewhere in the log, try searching for “exception”.

I found the problem :))).
the problem was, because i used booleans to change weapons, so i changed from Booleans to Enum, and now is working :))

Ahh, cool, good luck!

Thanks, you too!

1 Like