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
1
Question by Rukas90 · Apr 29, 2018 at 08:31 PM · prefabbuildgameobject.nameretrieve

Retrieve Object Prefab name

Hello, I am trying to retrieve object prefab name. I know that I can do that using:

 PrefabUtility.GetPrefabParent(gameObject).name

but the problem is that it only works inside editor. I'm working on the 'SelectionManager' in my game and right now I want to make double click on an object and select multiple same objects method, but I first want to somehow tag all the objects so that when I double click on a curtain object it would only select objects with the same type / tag. I thought about making an enum, but getting a name is much more simple and convenient.

Are there any ways in getting the prefab name outside the editor? Also maybe it's possible to somehow get the original gameObject name without counter tag?

Or are there any better way's in making something like this? Thank you

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 Cherno · Apr 29, 2018 at 08:36 PM 0
Share

If you have a GameObject variable and fill it with a reference to the prefab, you should be able to access it to get the name. Either as a public variable that can be assigned in the Editor before playing or at runtime via Resources.Load.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Serinx · Apr 29, 2018 at 10:32 PM

I think what you're looking for is Tags:

https://docs.unity3d.com/Manual/Tags.html

Tag all of your objects with the same tag, you can use FindGameObjectsWithTag to select them all.

 GameObject[] dogs;
 
 void Start()
 {
     dogs = GameObject.FindGameObjectsWithTag("dog");
 }
 
 void Update()
 {
    //Check for double click
    //if doubleclick then select all the dogs
       foreach (GameObject dog in dogs)
       {
              SelectionManager.Select(dog);
       }
 
 }

Obviously you'll need to flesh out the code a bit but you get the idea

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 Rukas90 · Apr 30, 2018 at 01:27 AM 1
Share

Thank you for the response!
Yes I suppose I could do it that why, but in the future I might end up with hundreds of different objects (like: props, buildings, units and ect..) so this could easily end up being really inconvenient for me.
Currently I have an "ObjectID" script attached to every object, I could add / create a name variable and then access that variable and check if the name is the same between all the objects, but I'm not sure if that's the best way tho..

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

112 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 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

Distribute terrain in zones 3 Answers

When compressing assets for .APK does whole projects assets get included? or just the scenes assets? prefabs? 1 Answer

Is it possible to create / replace prefab in builded game? 1 Answer

Big Prefabs Size 1 Answer

Prefabs in sub-folders not loading 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