Search Unity

Bug Unity Crashes badly during run-time...

Discussion in 'Editor & General Support' started by Gamo-Studios, May 8, 2023.

  1. Gamo-Studios

    Gamo-Studios

    Joined:
    Aug 24, 2022
    Posts:
    2
    Heya,

    so i was making a game for the pico day 2023 on newgrounds. i was trying to make something quite similar to Pico 2, and since it was quite bit complicated and this is my third game, and also due to bad specs, im having a hard time making this...

    so, coming to the point, the project crashes during a certain moment during run time.

    I was making a boss battle, that is just the replica of the boss battle in game, but remastered... https://www.youtube.com/watch?v=tZBVfmVZplo this is a link to it.

    briefing it, you cannot straightly shoot the boss. you've to shoot the 3 bodies it throws at you first. i store this at a int variable called bodyCount. if u get hit by one of the body, this variable resets. once it reaches 3, the boss turns to a confused state (which is not completed yet, but it still works, kinda).

    now the thing is, once this reaches 3..for some reason, unity gets hang. it does not respond, no clicks being registered cant even close it! absolutely ded. i had to 'end task' it on task manager. i tried to export it to webgl (the platform i had to export this.) it shows the same problem. And it is frustrating. I asked many people help, i thought this should be due to bad code writing skills (it could be, who knows?). and i couldn't figure it out still...

    Please respond if u can, i already missed the deadline...

    HERES MORE INFO:

    Version i use: 2021.3.21f1 [LTS]
    Type of game: 2d
    Any render pipeline installed? : Nope
    Size of project: approximately about 2.1 GB

    if u need anything else, u may ask. also, feel free to dm me on this issue. StiKDev#1221 i would be grateful u do.dm me for the files...because it is so big drive crashed twice (oof.) my time is on ist standard...so yeah.

    thanks in advance.
    stik
     
  2. Gamo-Studios

    Gamo-Studios

    Joined:
    Aug 24, 2022
    Posts:
    2
    Also, as i mentioned earlier, it could be due to bad code... so i can paste the code here. I use 2 scripts mainly.

    ALUCARD.CS:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Alucard : MonoBehaviour
    7. {
    8.     public int health = 20;
    9.  
    10.     [SerializeField] Slider healthBar;
    11.     public KidBall kidBall;
    12.  
    13.     public Animator animator;
    14.     [SerializeField] Camera mCamera; //for clicking retection with uses of raycast
    15.     public enum AlucardStates // this shows what animmation is being played in script
    16.     {
    17.         Walk,
    18.         Confused,
    19.         Dead
    20.     }
    21.  
    22.     public AlucardStates alucardState = AlucardStates.Walk;
    23.     RaycastHit hit;
    24.  
    25.     Transform playerPos;
    26.     public float speed = 2f;
    27.  
    28.     // Patrolling points
    29.     public GameObject pointA;
    30.     public GameObject pointB;
    31.     public bool confused = false;
    32.  
    33.    
    34.  
    35.     [SerializeField] Transform objToBeMoved;
    36.     [SerializeField] Transform[] points;
    37.     [SerializeField] Vector3 targetPos;
    38.     [SerializeField] float Speed;
    39.     [SerializeField] int currentPointIndex;
    40.     [SerializeField] bool loop;
    41.     public bool isMoving = true;
    42.     public bool isAlive = true;
    43.     public bool isShootable = false;
    44.  
    45.     Transform currentPoint; // for patroling and to which point to goto.
    46.  
    47.     private void Start()
    48.     {
    49.         //-------------SETTING UP--------------
    50.         playerPos = GameObject.FindGameObjectWithTag("Player").transform;
    51.         kidBall = FindObjectOfType<KidBall>();
    52.         animator = GetComponent<Animator>();
    53.         healthBar.GetComponent<Slider>().value = health;
    54.         currentPoint = pointA.transform;
    55.         animator.SetBool("isAlive", isAlive);
    56.         animator.SetBool("Confused", confused);
    57.         animator.SetBool("isMoving", isMoving);
    58.         //---------------------------------------
    59.         kidBall.ThrowBodies();
    60.  
    61.     }
    62.  
    63.     private void Update()
    64.     {
    65.         Follow();
    66.  
    67.         while(kidBall.bodyCount >= 3)
    68.         {
    69.             BackToNormal();
    70.         }
    71.         if(kidBall.bodyCount == 3)
    72.         {
    73.             confused = true;
    74.             isMoving = false;
    75.             isShootable = true;
    76.            
    77.         }
    78.  
    79.  
    80.  
    81.         if (isShootable && Input.GetMouseButtonDown(0))
    82.         {
    83.             RaycastHit2D rayHit = Physics2D.GetRayIntersection(mCamera.ScreenPointToRay(Input.mousePosition));
    84.             if (rayHit.transform != null && rayHit.transform == transform)
    85.             {
    86.                 health--;
    87.                 print("Clicked the enemy in alucard stuff cs");
    88.             }
    89.  
    90.         }
    91.  
    92.         if(health == 0)
    93.         {
    94.             isAlive= false;
    95.             isMoving = false;
    96.             confused = false;
    97.         }
    98.     }
    99.  
    100.     public void BackToNormal()
    101.     {
    102.         confused= false;
    103.         isMoving = true;
    104.         isShootable = false;
    105.     }
    106.  
    107.     public void Follow()
    108.     {
    109.         if (points == null || points.Length == 0)
    110.         {
    111.             Debug.Log("Please assign the points");
    112.            
    113.         }
    114.  
    115.         if (currentPointIndex < 0 || currentPointIndex > points.Length - 1)
    116.         {
    117.             Debug.Log($"Current Index is out of bounds : {currentPointIndex}");
    118.            
    119.         }
    120.  
    121.         targetPos = points[currentPointIndex].position;
    122.         Debug.Log($"Going to point : {currentPointIndex + 1} Position : {targetPos}");
    123.         if (isMoving)
    124.         {
    125.             objToBeMoved.position = Vector3.MoveTowards(objToBeMoved.position, targetPos, Speed * Time.deltaTime);
    126.             if (objToBeMoved.position == targetPos)
    127.             {
    128.                 if (currentPointIndex < points.Length - 1)
    129.                 {
    130.                     currentPointIndex++;
    131.                     Debug.Log($"Point Index increased to {currentPointIndex}");
    132.                    
    133.                 }
    134.                 else
    135.                 {
    136.                     if (loop)
    137.                     {
    138.                         Debug.Log("Starting point loop!");
    139.                         currentPointIndex = 0;
    140.                        
    141.                     }
    142.  
    143.                     Debug.Log("All points reached [Loop is Disabled]");
    144.                 }
    145.             }
    146.         }
    147.         else
    148.         {
    149.             objToBeMoved.position = transform.position;
    150.         }
    151.        
    152.     }
    153.  
    154. }
    AND KIDBALL.CS

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class KidBall : MonoBehaviour
    6. {
    7.     public Animator alucardAnim;
    8.     public GameObject spawnPoint;
    9.     public GameObject movePointB;
    10.     public float speed = 2f;
    11.     public GameObject player;
    12.     public int bodyCount = 0; // how much times the body has been shot. resets when player gets hit by one
    13.     RaycastHit hit;
    14.     public Camera mCamera;
    15.     public GameObject[] bodies;
    16.     GameObject instantiatedObject;
    17.     [SerializeField] Transform[] points;
    18.     [SerializeField] int currentPointIndex;
    19.     Vector3 targetPos;
    20.  
    21.  
    22.     public void ThrowBodies()
    23.     {
    24.         instantiatedObject = null;
    25.         if (alucardAnim.GetBool("isAlive") == true)
    26.         {
    27.             if (spawnPoint != null)
    28.             {
    29.                 int randnum = Random.Range(0, 2);
    30.                 if (instantiatedObject == null)
    31.                 {
    32.                     currentPointIndex = 0;
    33.                     instantiatedObject = Instantiate(bodies[randnum], spawnPoint.transform.position, Quaternion.identity);
    34.                 }
    35.             }
    36.         }
    37.     }
    38.     private void Update()
    39.     {
    40.  
    41.         if (instantiatedObject != null && currentPointIndex >= 0 && currentPointIndex <= points.Length - 1)
    42.         {
    43.             targetPos = points[currentPointIndex].position;
    44.             //Debug.Log($"Going to point : {currentPointIndex + 1} Position : {targetPos}");
    45.             instantiatedObject.transform.position = Vector3.MoveTowards(instantiatedObject.transform.position, targetPos, speed * Time.deltaTime);
    46.             if (instantiatedObject.transform.position == targetPos)
    47.             {
    48.                 if (currentPointIndex < points.Length - 1)
    49.                 {
    50.                     Debug.Log("Point Index increased!");
    51.                     currentPointIndex++;
    52.                 }
    53.                 else
    54.                 {
    55.                     Debug.Log("Point Index increased!");
    56.                     bodyCount = 0;
    57.                     Destroy(instantiatedObject);
    58.  
    59.                     if(bodyCount != 3)
    60.                     {
    61.                         ThrowBodies();
    62.                     }
    63.                     else
    64.                     {
    65.  
    66.                     }
    67.                    
    68.                 }
    69.             }
    70.  
    71.         }
    72.         print(bodyCount);
    73.  
    74.  
    75.         if (Input.GetMouseButtonDown(0))
    76.         {
    77.             RaycastHit2D rayHit = Physics2D.GetRayIntersection(mCamera.ScreenPointToRay(Input.mousePosition));
    78.             if (rayHit.transform != null && rayHit.transform == instantiatedObject.transform)
    79.             {
    80.                 bodyCount++;
    81.                 print("CAN U SEE THIS???");
    82.                 Destroy(instantiatedObject);
    83.                 if(bodyCount != 3)
    84.                 {
    85.                     ThrowBodies();
    86.                 }
    87.                 else
    88.                 {
    89.                     print("alucard is now confused");
    90.                 }
    91.  
    92.  
    93.                
    94.             }
    95.         }
    96.     }
    97. }
    98.  
    99.  
    100.