- Home /
The type or namespace name `SingletonMonoBehaviour`1' could not be found
hi,I have this issue in my project when public to wp ,there are no error on other platform
The type or namespace name SingletonMonoBehaviour
1' could not be found, Are you missing a using directive or an assembly reference?
and my full code like this
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
public class SingletonMonoBehaviour : MonoBehaviour where T : SingletonMonoBehaviour
{
private static SingletonMonoBehaviour<T> uniqueInstance;
public static bool Exists
{
get;
private set;
}
public static T Instance
{
get
{
SingletonMonoBehaviour<T>.Exists;
return (T)SingletonMonoBehaviour<T>.uniqueInstance;
}
}
public SingletonMonoBehaviour()
{
}
protected virtual void Awake()
{
if (SingletonMonoBehaviour<T>.uniqueInstance == null)
{
SingletonMonoBehaviour<T>.uniqueInstance = this;
SingletonMonoBehaviour<T>.Exists = true;
}
else if (SingletonMonoBehaviour<T>.uniqueInstance != this)
{
throw new InvalidOperationException(string.Concat("Cannot have two instances of a SingletonMonoBehaviour : ", typeof(T).ToString(), "."));
}
}
protected virtual void OnDestroy()
{
if (SingletonMonoBehaviour<T>.uniqueInstance == this)
{
SingletonMonoBehaviour<T>.Exists = false;
SingletonMonoBehaviour<T>.uniqueInstance = null;
}
}
}
public class EasySingleton : SingletonMonoBehaviour
{
}
can somebody show me how to fixed this issue?
Here is a similar thread: http://answers.unity3d.com/questions/154755/base-character-error.html
public class EasySingleton : Singleton$$anonymous$$onoBehaviour<EasySingleton>
{
}
sorry for type error,my class was like that with T generic parameter,
and what I want ask why I put my Singleton$$anonymous$$onoBehaviour to dll and public to WP8 and that error
sometime is not show? maybe my dll was wrong that is not the stand wp8 dll?
Answer by fafase · Nov 24, 2014 at 02:16 PM
When you get an error like Type 1 it means you have a problem with generic. Now looking at your code, I think you meant your class declaration to be:
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : SingletonMonoBehaviour
{}
But think this is just the beginning of more problem since many of your line seem to go wrong, for instance the second line should be:
public static T uniqueInstance;
Answer by Bunny83 · Nov 24, 2014 at 02:20 PM
Your class is missing the generic parameter. Take a look at this one. Also inside the class you should use your generic type variable when you're declaring a variable of that type.
Finally to use the generic class as base class you have to do:
public class EasySingleton : SingletonMonoBehaviour<EasySingleton>
{
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can't use Namespaces with Mono and 1 class 1 namespace file 1 Answer
Flip over an object (smooth transition) 3 Answers