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 uanmanarmy · Aug 13, 2014 at 08:30 AM · c#gameobjectfindgameobject.find

GameObject.Find, When it is Called?

Hey I need your help guys.

Can you tell me if GameObject.Find is called when The Game Only Starts or when you want it.

Cuz Im searching for some gameObjects, and they are not found

 public Vector3 blueScale;
 public Vector3 orangeScale;
 public Vector3 yellowScale;
 public Vector3 purpleScale;
 public Vector3 greenScale;
 public Vector3 redScale;
 
 
 public float blueEnergy;
 public float greeEnergy;
 public float orangeEnergy;
 public float purpleEnergy;
 public float redEnergy;
 public float yellowEnergy;
 
 
 public  Transform blue ;
 public  Transform green;
 public  Transform orange;
 public  Transform purple;
 public  Transform red;
 public  Transform yellow;
 
 public  GameObject _blue;
 public  GameObject _green;
 public  GameObject _orange;
 public  GameObject _purple;
 public  GameObject _red;
 public  GameObject _yellow;


 void Start()
 {

     FindItemsObjects (out _blue);
 }

 void Update()
 {
     //Debug.Log (_blue);
 }

 void OnGUI()
 {
     if(GUI.Button(new Rect(10,120,100,50), "New Level"))
     {    
         
         FindItemsObjects(out _blue);
     }
 }

 public void FindItemsObjects(out GameObject _sds)
 {
     Debug.Log ("Here Im searching");
     _sds = GameObject.FindWithTag ("Blue");
     WhenYouDoSomething (_sds, out blue, out blueScale);
     Debug.Log (_sds);
     _green = GameObject.FindWithTag ("Green");
     WhenYouDoSomething (_green, out green, out greenScale);

     _orange = GameObject.FindWithTag ("Orange");
     WhenYouDoSomething (_orange, out orange, out orangeScale);

     _purple = GameObject.FindWithTag ("Purple");
     WhenYouDoSomething (_purple, out purple, out purpleScale);

     _red = GameObject.FindWithTag ("Red");
     WhenYouDoSomething (_red, out red, out redScale);

     _yellow = GameObject.FindWithTag ("Yellow");
     WhenYouDoSomething (_yellow, out yellow, out yellowScale);
 }

 public Transform FindChild(GameObject parent, string name)
 {
     if (parent.name == name)
     {
         Debug.Log("Parent's Name is same as you are searching for");
         return null;
     }
     
     Transform pTransform = parent.GetComponent<Transform> ();
     foreach (Transform t in pTransform)
     {
         if (t.name == name) 
         {
             return t;
         }
     }
     return null;
 }
 
 
 public void WhenYouDoSomething(GameObject item, out Transform itemTransform, out Vector3 itemScale)
 {
     if (item == null)
     {
         Debug.Log ("Item is null");
         itemTransform = null;
         itemScale = Vector3.zero;
     }

     else
     {
         itemTransform = FindChild (item, "line");
         itemScale = itemTransform.localScale;
     }
 }

as you can see When I start the game, and put in the Update Function a Debug.Log of blue, the Log will give me a value. But after I press new Level, the blue value will be null.

Does this mean that it's not searching for other values after the game is started?

need HELLP!!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by markzareal · Aug 13, 2014 at 08:36 AM

it depends on what function you use it on. Like say void OnMouseDown the gameobject.find is only called when it is pressed. void start is only called once at the start, void update is called each frame, void OnMouseUp is called when you release.

Comment
Add comment · Show 2 · 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 uanmanarmy · Aug 13, 2014 at 08:52 AM 0
Share

So every Time I press on the NewLevelButton, it will search for the objects NO ?

avatar image uanmanarmy · Aug 13, 2014 at 08:53 AM 0
Share

Then Why it's not finding the new GameObject (((

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

22 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

Related Questions

Why does IsSleeping() keep returning false? (Billiard Logic) 0 Answers

Distribute terrain in zones 3 Answers

C# Gameobject's Script's ValuesEquals Other Gameobject's script's Values 1 Answer

adding animation dynamically by script 0 Answers

Null Reference Exception Error(Solved) 0 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