Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Aladine · Nov 10, 2013 at 04:39 AM · gameobjectfindmissing

GameObjet.find give "Missing"

Hello everyone, am facing a strange problem here, i have a class named "MainCowboy" and game objects that use this class are with tag "cowboy", these objects are a child of prefabs (lvl1, 2, 3, etc..)
now the problem is when i load a level (any) for the first time, Game.Object.FindWithTag works perfectly as expected, however, once i load another level, the variable with type MainCowboy become "Missing (MainCowboy)" thank you EDIT : here is the class that contain the error, i removed all the unnecessary lines just to make it more clearer, the loadLevel() method is called when i press a GUI button in the guiManager class .

 using UnityEngine;
 using System.Collections;
 
 public class GameManger : MonoBehaviour
 {
     
     
     public MainCowboy cowBoy ;
     public GameObject[] prefabs ;
     public GameObject level;
 
     void Start ()
     {
         loadLevel (1);
         cowBoy = GameObject.FindWithTag ("cowboy").GetComponent<MainCowboy> ();
     }
     public void loadLevel (int id)
     {
         Destroy (level);
         level = Instantiate (prefabs [id], transform.position, transform.rotation)as GameObject;
         cowBoy = GameObject.FindWithTag ("cowboy").GetComponent<MainCowboy> ();
     }
 
     
 }
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 Cains · Nov 10, 2013 at 05:12 AM 0
Share

It would be easier to answer if you could give code from your class and the structure of your GameObjects.

avatar image Aladine · Nov 10, 2013 at 05:19 AM 0
Share

edited thank you

avatar image Cains · Nov 10, 2013 at 05:47 AM 0
Share

Is there an actual error co$$anonymous$$g up on your log? If so what's the exact error.

avatar image sdgd · Nov 10, 2013 at 05:54 AM 0
Share

from title I guess it's NRE missing game object, ...?

avatar image Aladine · Nov 10, 2013 at 02:18 PM 0
Share

@Cains8 no initially i don't get any error when that happens, however when i try to use "cowBoy" after that i get an error who say that the object doesn't exist

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Starwalker · Nov 10, 2013 at 08:55 AM

Whatever object you have this script applied to and the target object this script is referring to is getting destroyed on scene load. It happens by default.

Suggest using this: Dont destroy on load reference

The above code would keep the object alive between scene changes. And apply the same restriction to both objects in question depending on what you require to be alive and wake in the next scene.

Hope it helps

Comment
Add comment · Show 1 · Share
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 Aladine · Nov 10, 2013 at 02:20 PM 0
Share

thanx for your answer, but just for the reference, am not loading any new scene (unity scenes) the levels are prefabs and everything is happening in the same scene

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

20 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

Related Questions

All the objects in my script choose the same target. 2 Answers

A GameObject is missing in GameView 3 Answers

C# gameobject find and disable 1 Answer

Finding Assets/Prefabs That Are Not In The Scene 1 Answer

Find all objects that have a specific string. 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