Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by allouah991 · May 10, 2020 at 07:11 AM · transformobjectdestroymissingreferenceexception

,MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

I have problem that my player is not spawning MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.

{ public static GameMaster gm;

 [SerializeField]
 private int maxLives = 3;
 private static int _remainingLives;
 public static int RemainingLives
 {
     get { return _remainingLives; }
 }

 [SerializeField]
 private int startingMoney;
 public static int Money;

 void Awake()
 {
     if (gm == null)
     {
         gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
     }
 }

 public Transform playerPrefab;
 public Transform spawnPoint;
 public float spawnDelay = 2;
 public Transform spawnPrefab;
 public string respawnCountdownSoundName = "RespawnCountdown";
 public string spawnSoundName = "Spawn";

 public string gameOverSoundName = "GameOver";

 public CameraShake cameraShake;

 [SerializeField]
 private GameObject gameOverUI;

 [SerializeField]
 private GameObject upgradeMenu;

 public delegate void UpgradeMenuCallback(bool active);
 public UpgradeMenuCallback onToggleUpgradeMenu;

 //cache
 private AudioManager audioManager;
 private UnityEngine.Object clone;
 private object _enemy;

 void Start()
 {
     if (cameraShake == null)
     {
         Debug.LogError("No camera shake referenced in GameMaster");
     }

     _remainingLives = maxLives;

     Money = startingMoney;

     //caching
     audioManager = AudioManager.instance;
     if (audioManager == null)
     {
         Debug.LogError("FREAK OUT! No AudioManager found in the scene.");
     }
 }

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.U))
     {
         ToggleUpgradeMenu();
     }
 }

 private void ToggleUpgradeMenu()
 {
     upgradeMenu.SetActive(!upgradeMenu.activeSelf);
     onToggleUpgradeMenu.Invoke(upgradeMenu.activeSelf);
 }

 public void EndGame()
 {
     audioManager.PlaySound(gameOverSoundName);

     Debug.Log("GAME OVER");
     gameOverUI.SetActive(true);
 }

 public IEnumerator _RespawnPlayer()
 {
     yield return new WaitForSeconds(spawnDelay);

     Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
     Transform clone = (Transform)Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation);
 }

 public static void KillPlayer(Player player)
 {
     Destroy(player.gameObject);
     _remainingLives -= 1;
     if (_remainingLives <= 0)
     {
         gm.EndGame();
     }
     else
     {
         gm.StartCoroutine(gm._RespawnPlayer());
     }
 }

 public static void KillEnemy(Enemy enemy)
 {
     gm._KillEnemy(enemy);
 }
 public void _KillEnemy(Enemy _enemy)
 {
     // Let's play some sound
     audioManager.PlaySound(_enemy.deathSoundName);

     // Add particles
     GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
     Destroy(_clone, 5f);
 }

 private class AudioManager
 {
     internal static readonly AudioManager instance;

     internal void PlaySound(string gameOverSoundName)
     {
         throw new NotImplementedException();
     }
 }

} ,

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image icehex · May 10, 2020 at 07:19 AM 0
Share

I thought about reading through your code to figure out what line the error is on, but thought better of it. Post the full error or at least tell us which line is causing it :-/

avatar image allouah991 icehex · May 10, 2020 at 07:38 AM 0
Share

even unity is not telling me where is the error in my C# coding jst this ($$anonymous$$issingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) (at :0) UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0) UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0) Game$$anonymous$$aster+<RespawnPlayer>d_27.$$anonymous$$oveNext () (at Assets/Player/Game$$anonymous$$aster.cs:100) UnityEngine.SetupCoroutine.Invoke$$anonymous$$oveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0) )

avatar image icehex allouah991 · May 10, 2020 at 07:49 PM 0
Share

That there tells you part of the error is traced through line 100 of Game$$anonymous$$aster.cs, so it would be helpful to include the entire Game$$anonymous$$aster.cs script in your question and to also point out which line 100 is

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to diappear a line renderer from start and end position of line 1 Answer

MissingReferenceException Help 1 Answer

Child instantiated object to RayCastHit's parent. 1 Answer

MissingReferenceException error. 1 Answer

Camera Orbiting Character: How to make an object move with another with no rotation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges