Search Unity

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:
    146
    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:
    175
    Hey not sure what you mean stay GameObjects stable
    Mind post the code by code tag ?
     
  3. huseyinbaba58

    huseyinbaba58

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

    Flynn_Prime

    Joined:
    Apr 26, 2017
    Posts:
    387
    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:
    146
    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:
    7,909
    You have some code somewhere that is either destroying or disabling the object.
     
  7. huseyinbaba58

    huseyinbaba58

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

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    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:
    146
    Error is caused by line 31. Error message marks to this row.
     
  10. chrische5

    chrische5

    Joined:
    Oct 12, 2015
    Posts:
    52
    Hello

    Why you dont Show us some Code?

    Christoph
     
  11. huseyinbaba58

    huseyinbaba58

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

    Yanne065

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

    huseyinbaba58

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

    mgrekt

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