• 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 iwe2 · Jul 27, 2014 at 08:27 AM · gameobject

MissingReferenceException: The object of type 'GameObject' 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.

Hello there,

this is a script

using UnityEngine; using System.Collections;

public class GameController : MonoBehaviour {

 /// <summary>
 /// The flasica.
 /// </summary>
 public GameObject flasica;
 private float maxHigh;

 void Start () {
 
     Vector3 targetHigh = new Vector3 (-8.5f, -5.0f, 0.0f);
     float flasicaHigh = flasica.renderer.bounds.extents.x;
     maxHigh= targetHigh.x - flasicaHigh;
     StartCoroutine (Spawn ());
             } 
 IEnumerator Spawn () {
     yield return new WaitForSeconds (2.0f);
     while (true) {
         Vector3 spawnPosition = new Vector3 (
             Random.Range (-maxHigh, maxHigh),
             transform.position.y,
             0.0f
             );
         Quaternion spawnRotation = Quaternion.identity;
         Instantiate (flasica, spawnPosition, spawnRotation);
         yield return new WaitForSeconds (Random.Range (1.0f,2.5f));
     }
 }

}

And this is a problem:

MissingReferenceException: The object of type 'GameObject' 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, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:74) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:84) GameController+c__Iterator0.MoveNext () (at Assets/scripte/GameController.cs:28)

Can you help me, please to solve this?

Comment
Add comment · Show 5
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 incorrect · Jul 27, 2014 at 08:47 AM 0
Share

You did not assigned anything to 'flasica'.

avatar image Norax · Jul 27, 2014 at 09:07 AM 0
Share

flasica is public and he uses it at line 10 (which differs from the line of the error). So I would say he probably just added it via editor. If line 10 don't throw an error, it doesn't make sense to crash at line 23.

flasicaHigh has been assigned correctly?

avatar image DajBuzi · Jul 27, 2014 at 09:18 AM 0
Share

it's something with instantiating, I think that you've assigned simple GameObject from hierarchy ins$$anonymous$$d of adding it from some kind of Prefab. This is the common issue dropping that error.

To solve this make sure flasica variable is referencing Prefab object from your asstes.

avatar image incorrect · Jul 27, 2014 at 09:55 AM 0
Share

It crashes at Instantiate (flasica, spawnPosition, spawnRotation); So it is not something wrong with spawnPosition as it was assigned new Vector3 and spawnRotation was assigned Quaternion.Identity.

avatar image tanoshimi · Jul 27, 2014 at 10:12 AM 0
Share

I tend to agree with @DajBuzi - it seems likely that flasica is an object in the scene that has been destroyed, rather than a prefab.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Place gameobject on ROI 0 Answers

How would I be able to subtract from a variable when it hits something? (OnCollisionEnter) 1 Answer

Lobby - Trouble with custom feature 1 Answer

Activate gameobject that is deactivated with c# 2 Answers


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