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 casteponters · Mar 23, 2015 at 06:44 PM · canvastagfindactivate

Find GameObject in Canvas

Hi all. I have one problem with my script in C#. I try to find one Game object that is in one Canvas. But the script not found.

I try with:

     GameObject.Find("Star_1").SetActive(true);
     
     OR
     
     GameObject.FindGameObjectWithTag("Star_1").SetActive(true);


if I put it out of the canvas work. How can i do?

Comment
Add comment · Show 2
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 Huacanacha · Mar 23, 2015 at 07:10 PM 0
Share

Is the game object inactive in the hierarchy when placed under the canvas? GameObject.Find will only find active objects. Otherwise double check the exact name and make sure the tag is applied.

avatar image casteponters · Mar 23, 2015 at 08:04 PM 0
Share

yes it's inacative. How can i find?

2 Replies

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

Answer by Huacanacha · Mar 23, 2015 at 08:58 PM

Per your reply the problem is that the gameobject is inactive. Find only returns active objects.

There are two ways to find inactive objects that I know of:

  • Resources.FindObjectsOfTypeAll - you can search by script (better) or by GameObject then find the object you want in the returned list. SLOW.

  • Manually searching the transform tree. In your case you could start at the canvas object. Can be slow.

However, I suggest you rethink your approach to the problem. If the object exists in the scene hierarchy at design time (i.e. not added via Instantiate or streamed assets) then just setup a reference to it in the inspector. Have a public field in the script that needs to access the script you are trying to find, then assign it in the editor. This will also avoid any performance hit.

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

Answer by Pharaoh_ · Mar 23, 2015 at 07:27 PM

What if you derive it from the Canvas? Canvas.FindObjectOfType?

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

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

23 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

Related Questions

character collider colliding with another character collider 1 Answer

Whats the best way to access other Game Objects? 2 Answers

Find how many are there in the scene 1 Answer

Camera.main look up 1 Answer

Activating something on multiple objects 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