- Home /
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
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.
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.
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.
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);
}
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.
it's just a matter of notation
the computational difference is negligible
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.
That's a neat trick, I've never used it this way because if figured the opposing scope would throw an error
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)
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.
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?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
Singleton usage wherever possible? GAWSANA in Unity? 3 Answers
Singleton code and Unify down. 1 Answer