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 dalioto · Dec 15, 2014 at 07:24 PM · objectnamespaceassign

Cannot assign script to objects when class is within a Namespace

I have a namespace that is a collection of classes that all need to know about each other. I want to be able to assign these different classes to objects. However, when I go to Add Component the Foo script file does not show up as a choice.

I have read some other issues related to this and they all seem to be based on default parameters. But as you can see I am not using any default params. Is there some other reason that my classes are not showing up as available scripts to assign to objects?

 namespace Foo
 {

     public enum mytype { Basic, Standard, Deluxe, Premium };

     public class Owner : MonoBehaviour
     {
         private string _name;
         private double _cash;
         private double _networth;
 
         public Owner()
         {
             _cash = 100000.00;
             _networth = _cash;
         }
 
         public string name
         {
             get { return _name; }
             set { _name = name; }
         }
         public double cash
         {
             get { return _cash; }
             set { _cash = cash; }
         }
         public double networth
         {
             get { return _networth; }
             set { _networth = networth; }
         }
     }
 }
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 VesuvianPrime · Dec 15, 2014 at 07:24 PM 0
Share

Can you post the namespace? I'm wondering if there's a conflict between namespace and class name.

avatar image meat5000 ♦ · Dec 16, 2014 at 12:58 PM 0
Share

Access your namespace with the 'using' directive.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by VesuvianPrime · Dec 15, 2014 at 10:03 PM

Good catch on constructor.

MonoBehaviours didn't used to work in namespaces, but in Unity 4 they absolutely do.

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 Paulius-Liekis · Dec 15, 2014 at 08:36 PM

I think you're not supposed to use constructors for MonoBehaviours - you should use Awake and Start methods.

MonoBehaviours in namespaces might be not supported, I don't remmember exactly.

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 dalioto · Dec 16, 2014 at 12:56 PM 0
Share

I commented out the Constructor. That made no difference. The namespace still does not show up in the scripts.

The class name and the namespace have completely different names.

I even tried commenting out the Enums as well.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Necessary to remove unused scripts from imported packages for deployment? 1 Answer

[C#]Adding a Sprite from a Resources.Load("Path") : How does it work ? 3 Answers

get all scripts attached to gameobject 2 Answers

How to keep a moving object at the height of the terrain? (script) 2 Answers

InstanceIDtoObject namespace? 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