Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 abstractfragment · Feb 09, 2018 at 12:49 AM · instantiateprefabstriggerstags

Unity 2017 Not finding prefab tag

I have these prefab trackers drop from the player as he walks around. The enemy character is meant to stumble onto these trackers and eventually that will turn into him following the player's footsteps in order. However for some reason the enemy's trigger will not find the tagged prefabs. They are tagged on the prefab in the assets folder. If I drag and drop the prefab onto the scene it will not find the tag for the prefab game object but say for example I change the players tag it will find that. I'm not sure what's going on here. Instantiate script

 void poopPrefab() {
         Transform footstepPrefab = Instantiate (footPrefab, currentPos, currentRot);
     }

Tag finder script

     void OnTriggerStay(Collider col)
     {
         if (col.tag == ("tracking")) {
             Debug.Log ("a thing has happened");
         }


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
0
Best Answer

Answer by melsy · Feb 09, 2018 at 12:53 AM

 const string tag = "tracking";
 If (col.CompareTag(tag))
     //Do something
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 abstractfragment · Feb 09, 2018 at 02:40 AM 0
Share

No dice. Tried implementing as.

 void OnTriggerStay(Collider col)
     {
         const string ftag = "tracking";
         if (col.CompareTag(ftag)) {
             Debug.Log ("a thing has happened");
         }
         
     }
avatar image melsy · Feb 09, 2018 at 02:59 AM 1
Share

What components are on it. A trigger needs to find an object collision with a rigidbody.

avatar image abstractfragment melsy · Feb 09, 2018 at 03:02 AM 0
Share

Haha! I literally just figured this out myself and was about about to close this when I saw you responded. Yes all it needed was a rigidbody thank you.

avatar image melsy · Feb 09, 2018 at 03:09 AM 0
Share

That's the way it usually works lol. But for future reference the string doesn't need to be in separate perens. Also move the const string declaration to the top of the class. It's more efficient to create strings as const so they don't get recreated every time they get called

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

97 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Invisable Projectile; Instantiate at Collisions 2 Answers

Need help understanding scripted prefab behavior - when I click one, the script runs on ALL prefab instances, not just the one I clicked. 3 Answers

Animations on instantiated prefabs not working 0 Answers

Want a script that can instantiate an object when MOVING inside the trigger 1 Answer

Instantiate an object in a prefab? 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