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 /
avatar image
0
Question by Domvel · Oct 23, 2018 at 03:40 PM · c#singletonconflict

Singleton Class Name Conflict

I just trying to create a singleton for static global variables.

 public class SingletonController : MonoBehaviour {
   public static SingletonController instance { get; private set; } // <- fails
   // etc.
 }


Error: SingletonController name conflict with the class name SingletonController. (Conflict with Assembly-CSharp-firstpass)



Unity Version2018.2.13f1

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Domvel · Oct 23, 2018 at 04:48 PM

Solution: Just restart Unity. If it still crying try to delete the Library folder from the project.

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 Vicarian · Oct 23, 2018 at 05:08 PM 0
Share

Please mark this as the answer to close this question.

avatar image Domvel Vicarian · Oct 23, 2018 at 05:11 PM 0
Share

I really tried. But this website (Unity answers is very buggy) :D e.g. my post wasn't visible, the show more comments doesn't work ... and and and... I already sent a feedback suggestion to fix this bugs. but anyway. thanks ^^ Btw. also here is a restart helpful. But not always. Glitchy page.

avatar image Vicarian Domvel · Oct 23, 2018 at 05:13 PM 0
Share

It's all good - you couldn't mark it as an answer because you happened to write it as a comment on your original post.

Show more comments
avatar image
1

Answer by GamitusLabs · Oct 23, 2018 at 03:53 PM

Don't even give them the set option...

 private static SingletonController instance = null;

 public static SingletonController Instance
 {
     get { return instance; }
 }

 void Awake()
 {
     if (!instance)
     {
         instance = transform.GetComponent<SingletonController>();
         DontDestroyOnLoad(instance);
     }
     else
         Destroy(gameObject);
 }

Comment
Add comment · Show 5 · 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 Bunny83 · Oct 23, 2018 at 04:10 PM 0
Share

Why do you use transform? And why do you actually use GetComponent? just do

 instance = this;

Currently you actually do

 instance = this.GetComponent<Transform>().GetComponent<SingletonController>();

Though i don't think that this is actually the issue here. The property he has should work just fine. I guess he has another class somewhere in his project with the same name. Since the error mentions "Assembly-CSharp-firstpass" that class is declared inside a plugins or Standard Assets folder.

avatar image GamitusLabs Bunny83 · Oct 23, 2018 at 04:27 PM 0
Share

it's just a matter of notation

the computational difference is negligible

avatar image Vicarian · Oct 23, 2018 at 04:20 PM 0
Share

private set just means that the set can only be accessed from the class the property is declared in. No other class will have access to the set, but will be able to access the get. It's basically exactly what you want with the Singleton pattern.

avatar image Domvel Vicarian · Oct 23, 2018 at 04:22 PM 0
Share

Correct, it's just a shorter code to do this. :)

avatar image GamitusLabs Domvel · Oct 23, 2018 at 05:14 PM 0
Share

That's a neat trick, I've never used it this way because if figured the opposing scope would throw an error

avatar image
0

Answer by Domvel · Oct 23, 2018 at 04:05 PM

Thanks for response, but the set option isn't the problem. At the moment, it seems so. Maybe a pseudo error?
See the underlined conflicts with the name. (of my first post)


screen.png (35.1 kB)
Comment
Add comment · Show 6 · 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 GamitusLabs · Oct 23, 2018 at 04:11 PM 0
Share

is your file name different from your class name?

avatar image Domvel GamitusLabs · Oct 23, 2018 at 04:16 PM 0
Share

In both cases same problem. I change the name of the class. The problem message tells about "Conflict with Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=natural, Public$$anonymous$$eyToken=null". Followed by "the defined type is used." That's weird.

avatar image Vicarian Domvel · Oct 23, 2018 at 04:30 PM 0
Share

So you created SingletonTest as a fresh class and it's not getting used elsewhere? I wonder if something happened with your Asset Database. $$anonymous$$aybe delete the Library folder and have Unity rebuild it?

Show more comments
Show more comments

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

96 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Question About Singleton Pattern 2 Answers

Chartboost and Facebook conflict 0 Answers

Where would I call the DoDestroyOnLoad function on my Singleton Script 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