I have been using the following base class for singleton components: using UnityEngine; using System.Collections;
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
protected static T instance;
Returns the instance of this singleton.
public static T Instance
if(instance == null)
instance = (T) FindObjectOfType(typeof(T));
if (instance == null)
" instance is missing.");
Today I tried making a virtually identical class that inherited from NetworkBehavior because I had some networked game manager scripts that I wanted easy access to. So I just switched out MonoBehavior for NetworkBehavior. Things built fine in mlnodevelop, but the editor console immediately gave me. "UNetWeaver error: NetworkBehaviour NetworkSingleton`1 cannot have generic parameters," and reported failure generating network code.
I'm curious what is causing this, and would like to know if there is an easy way implement singleton a singleton base class for network behaviors.
Answer by ghostravnestorm
3 days ago
Bump. I need to know this too. I have a Game Manager singleton that extends Network Behaviour, but its variables are null when clients try to access it.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
57 People are following this question.
OnDisconnectedFromServer ignores inheritance
MonoBehaviour Inheritance, Singletons and Generics
Unity networking tutorial?
An OS design issue: File types associated with their appropriate programs
UNET Rpc calls wrong inherited script