• 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 layola · Nov 24, 2014 at 02:14 PM · c#namespaceassembly

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 SingletonMonoBehaviour1' 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?

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 SaraCecilia · Nov 24, 2014 at 02:17 PM 0
Share

Here is a similar thread: http://answers.unity3d.com/questions/154755/base-character-error.html

avatar image layola · Nov 25, 2014 at 04:37 PM 0
Share
  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?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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;

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 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>
 {
 }

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

error CS0246: The type or namespace name `List' could not be found. 1 Answer

Namespace Functions not being recognized 0 Answers

Namespaces usage recommendation 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