- Home /
MethodAccessException: Attempt to access a private/protected method failed.
MethodAccessException: Attempt to access a private/protected method failed. at System.Security.SecurityManager.ThrowException (System.Exception ex) [0x00000] in :0
at ProfileManager..ctor () [0x00000] in :0 UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) UnityEngine.GameObject:.ctor(String, Type[]) MonoSingleton`1:get_instance() MainMenus:RefreshUsernameCache()
Had this in web player, however no issues in the PC version. Any idea how to fix this? This is the code for the singleton.
using UnityEngine;
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
private static T m_Instance = null;
public static T instance
{
get
{
// Instance requiered for the first time, we look for it
if( m_Instance == null )
{
m_Instance = GameObject.FindObjectOfType(typeof(T)) as T;
// Object not found, we create a temporary one
if( m_Instance == null )
{
Debug.LogWarning("No instance of " + typeof(T).ToString() + ", a temporary one is created.");
m_Instance = new GameObject("Temp Instance of " + typeof(T).ToString(), typeof(T)).GetComponent<T>();
// Problem during the creation, this should not happen
if( m_Instance == null )
{
Debug.LogError("Problem during the creation of " + typeof(T).ToString());
}
}
m_Instance.Init();
}
return m_Instance;
}
}
public T GetInstance()
{
return m_Instance;
}
// If no other monobehaviour request the instance in an awake function
// executing before this one, no need to search the object.
private void Awake()
{
if( m_Instance == null )
{
m_Instance = this as T;
m_Instance.Init();
}
}
// This function is called when the instance is used the first time
// Put all the initializations you need here, as you would do in Awake
public virtual void Init(){}
// Make sure the instance isn't referenced anymore when the user quit, just in case.
private void OnApplicationQuit()
{
m_Instance = null;
}
}
Your answer
Follow this Question
Related Questions
How would I go about getting the results of a javascript variable to a string inside script? 3 Answers
How to play unity web export in android web view 1 Answer
Unity Web Player administrator privileges 0 Answers
Real Time Refresh from Web Portal 0 Answers
Embedding a game onto a website with XAMPP and PHP 0 Answers