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

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?

Hey not sure what you mean stay GameObjects stable
Mind post the code by code tag ?

Game object disappeared suddenly while game was running.The game object was a duplicate another game object.

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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Atis : MonoBehaviour
{
    public Transform hedef;//Hedef nesne belirlendi.
    public GameObject mermi;//Mermi belirlendi.
 


    void Awake()
    {
      
    }
    void Update()
    {
      
      
            Atisma();
      
    }
    void Atisma()
    {
        transform.LookAt(hedef); //Hedefe yönelmek için
        if (mermi != null)
        {
            GameObject mermiler = Instantiate(mermi, transform.position, Quaternion.identity) as GameObject; //Örneklendirme yapıldı.
            GudumluFuze mermim = mermiler.GetComponent<GudumluFuze>();
            mermim.konum = transform.position;
            Destroy(mermim, 2f); //2 saniye sonra yok olacak.
        }
    }
}

I think this script cause error.

You have some code somewhere that is either destroying or disabling the object.

Yes. I understood.But I can’t find a solution.

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.

Error is caused by line 31. Error message marks to this row.

Hello

Why you dont Show us some Code?

Christoph

I shared script over the comments

Where

I shared script’s link above

Just read the code, especially that if statement. If mermi IS NOT EQUAL to null … DESTROY

1 Like