Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to prevent to disable game object while game is running in Unity?

Discussion in 'Scripting' started by huseyinbaba58, Aug 2, 2020.

  1. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    I am developing a simple game.I want to stay game object stable.However,While I am running game,game objects miss suddenly.How can I fix it?
     
  2. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    151
    Hey not sure what you mean stay GameObjects stable
    Mind post the code by code tag ?
     
  3. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    Game object disappeared suddenly while game was running.The game object was a duplicate another game object.
     
  4. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    365
    There are a million reasons why this could be happening. I may be exaggerating slightly but we need to some of your code (where you are creating and destroying your GameObject would be ideal) in order to be of any help
     
  5. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Atis : MonoBehaviour
    6. {
    7.     public Transform hedef;//Hedef nesne belirlendi.
    8.     public GameObject mermi;//Mermi belirlendi.
    9.  
    10.  
    11.  
    12.     void Awake()
    13.     {
    14.      
    15.     }
    16.     void Update()
    17.     {
    18.      
    19.      
    20.             Atisma();
    21.      
    22.     }
    23.     void Atisma()
    24.     {
    25.         transform.LookAt(hedef); //Hedefe yönelmek için
    26.         if (mermi != null)
    27.         {
    28.             GameObject mermiler = Instantiate(mermi, transform.position, Quaternion.identity) as GameObject; //Örneklendirme yapıldı.
    29.             GudumluFuze mermim = mermiler.GetComponent<GudumluFuze>();
    30.             mermim.konum = transform.position;
    31.             Destroy(mermim, 2f); //2 saniye sonra yok olacak.
    32.         }
    33.     }
    34. }
    35.  
    I think this script cause error.
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    2,404
    You have some code somewhere that is either destroying or disabling the object.
     
  7. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    Yes. I understood.But I can't find a solution.
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    2,404
    The solution is to find the code that's doing that.Hard for anyone on the forum to help beyond that without seeing your project and/or code.

    Let's think about this like Sherlock Holmes. When did this problem start happening? Were you working on one or more scripts at that time? Maybe the problem is in one of those scripts.
     
  9. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    Error is caused by line 31. Error message marks to this row.
     
  10. chrische5

    chrische5

    Joined:
    Oct 12, 2015
    Posts:
    15
    Hello

    Why you dont Show us some Code?

    Christoph
     
  11. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
    I shared script over the comments
     
  12. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    151
    Where
     
  13. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    49
  14. mgrekt

    mgrekt

    Joined:
    Jun 22, 2019
    Posts:
    51
    Just read the code, especially that if statement. If mermi IS NOT EQUAL to null ... DESTROY...
     
    Joe-Censored likes this.
unityunity