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 1illGamer · Feb 10, 2020 at 05:47 PM · script.componentnamespacecomponents

How to make namespaces appear in the AddComponent List automatically?

Let's say I have a component called Platform within the namespace Hardware. Then let's say I have another component Platform within the namespace GameEntity. Both inherit from monobehaviour.

So when I go to add a component to a gameobject from the add component menu I'll see two items named 'Platform'. Is there a way to tell which is which without adding them and checking the file.

Ideally the component list would read Hardware.Platform and GameEntity.Platform. And for the sake of this question, let's pretend that I can't just rename my scripts.

The best I can find right now is -> AddComponentMenu("Hardware.Platform")] <- at the top of each class but that doesn't actually remove the original 'Platform' from the component menu and I'd rather unity just use the namespaces automatically rather than having to do it manually each time.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ShadyProductions · Feb 10, 2020 at 05:56 PM

You can enforce a specific using by doing

 using Platform = Hardware.Platform;

then every Platform class in that script will reference to that specific one.

Or you could do AddComponent<Hardware.Platform>()

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 1illGamer · Feb 10, 2020 at 06:05 PM 0
Share

I'm specifically looking for how to make it appear like this in the AddComponent menu on game objects. Not how to use a namespace in a script.

avatar image ShadyProductions 1illGamer · Feb 10, 2020 at 06:10 PM 0
Share

I don't think you can do that other than rena$$anonymous$$g the script. Or using AddComponent$$anonymous$$enu

avatar image
0

Answer by Bunny83 · Feb 10, 2020 at 06:49 PM

You just have the wrong approach to begin with. I highly recommend you read the guidelines for namespaces.

Specifically:

DO NOT give the same name to types in namespaces within a single application model.


The main purpose of namespaces is to group things together which belong together. Namespaces are not meant to distinguish between different implementations of the same thing. Namespaces do help when you use third-party frameworks to avoid naming conflicts. Do not create nameconflicts on purpose within the same application. So use proper classnames which actually describe what that component does and what's the difference between your two classes.

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 1illGamer · Feb 11, 2020 at 01:08 PM 0
Share

Thanks, very interesting read. But I'm not looking for how to use namespaces. I'm looking for an easier way to make namespaces appear in the AddComponent menu.

avatar image Bonfire-Boy · Feb 11, 2020 at 05:41 PM 1
Share

You're right of course, that one should try to make class names distinct. But one doesn't always have full control over them.

Also, even when class names are all distinct, it might be useful to someone to be able to see from the AddComponent pop-up, what namespace a class is in.

Actually, for me what would be even more useful (and would effectively encompass the namespace thing) would be if there was a field showing you the path to the script when you hovered over it.

So if there were a way to customise that pop-up, I'd be very interested to hear about it. I imagine that there isn't, though. And I may just resort to using the attribute the OP mentioned, which I wasn't aware of before (so thanks, @1illGamer !)

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

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

Unity can't see any scripts 0 Answers

Add AudioSource-Like Range to Script 1 Answer

Destroy all scripts on object. 3 Answers

How do I show a custom dynamic string instead of the script name of a MonoBehaviour component in the Inspector? 1 Answer

What happened to conveniently replacing component scripts in the inspector? 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