Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
This question was closed Jun 16, 2016 at 01:32 PM by vernonfx for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by vernonfx · Jun 15, 2016 at 06:19 AM · gameobjecttagfindinactive

How to access an inactive gameObject with tag

Hello. I have a gameObject called playerWeaponsPrefab which has 4 children, the first child is tagged as PrimaryWeapon, the second is tagged as SecondaryWeapon, the third is tagged as Knife and the forth is a grenade, I want to select these weapons in game by pressing 1,2,3 and 4 buttons ( while a weapon is selected others must be inactive). I put these weapon gameObjects in 4 variables and used GameObject.FindwithTag(exampleWeapon) for accessing to them but I can not access to them and it returns null because the gameObject is not active. I was shocked when I saw GameObject.FindWithTag doesn't work on inactive Objects. what Should I do to access my inactive weapon? thanks for help in advance.

Comment
Add comment · Show 1
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 Brijs · Jun 15, 2016 at 10:41 AM 1
Share

this can help you

2 Replies

  • Sort: 
avatar image
10
Best Answer

Answer by Safforn · Jun 15, 2016 at 01:12 PM

Leave them enabled in the editor, get them with Start() and after you have them disable them.

You could also try making 4 public gameObjects and just drag your weapons in there.

 private void Start()
     {
         weapon = GameObject.FindGameObjectWithTag("tag");
         weapon.SetActive (false);
     }

Comment
Add comment · Show 4 · 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 vernonfx · Jun 16, 2016 at 08:27 AM 0
Share

Thanks. that solved my problem.

avatar image Safforn vernonfx · Jun 16, 2016 at 11:28 AM 0
Share

Nice! Could you mark the question as answered and accept my answer?

avatar image Mmmpies Safforn · Jun 16, 2016 at 12:05 PM 0
Share

Accepted for you.

avatar image cmkkkz · Nov 11, 2021 at 10:42 PM 0
Share

THANK YOU from the future

avatar image
0

Answer by Arshd · Jun 15, 2016 at 01:37 PM

You should have a pre-defined array with the weapons or a list if you want to add more in the future, i think it's better than always using any GameObject.Find

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 Safforn · Jun 15, 2016 at 01:42 PM 1
Share

Yeah I agree, that would be more efficient. He could also just make his gameobjects public and assign them from the inspector. Just drag and drop

avatar image Arshd Safforn · Jun 15, 2016 at 02:27 PM 0
Share

He could and that what i meant sorry if i wasn't clear :)

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

How is this done with UNİTY ? 1 Answer

Tag control 0 Answers

DontDestroyOnLoad() and GameObject.FindGameObjectWithTag() [C#] 1 Answer

How do I check if a child object exists? 5 Answers

Get nearest GameObject 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