Hi Guys,
So I made an EditorScript which lets me make items but thats not relevant, the point is that yesterday everything worked just fine and today when I opened Unity a message appeared which said that the layout system crashed or something similar. When the project opened, everyrtime I tried to open the Custom Editor Window I was getting the following error:
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
ItemCreator…ctor ()
Here is my script:
using UnityEngine;
using UnityEditor;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEditor.Events;
public class ItemCreator : EditorWindow
{
string m_ItemName;
float m_AttackDamage;
float m_BlastDamage;
float m_AttackSpeed;
float m_Armor;
float m_BlastResist;
float m_MovementSpeed;
bool m_HasActive;
Vector2 m_ScrollPos;
StoreBehaviour m_StoreBehaviour = GameObject.FindGameObjectWithTag("Store").GetComponent<StoreBehaviour>();
[MenuItem("Item Creator/Create Item #i")]
public static void ShowWindow()
{
ItemCreator window = (ItemCreator)EditorWindow.GetWindow (typeof (ItemCreator));
window.Show();
}
void OnGUI()
{
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, false, false);
GUILayout.Label("Main Settings", EditorStyles.boldLabel);
m_ItemName = EditorGUILayout.TextField("Item Name", m_ItemName);
m_AttackDamage = EditorGUILayout.FloatField("Attack Damage", m_AttackDamage);
m_BlastDamage = EditorGUILayout.FloatField("Blast Damage", m_BlastDamage);
m_AttackSpeed = EditorGUILayout.FloatField("Attack Speed", m_AttackSpeed);
m_Armor = EditorGUILayout.FloatField("Armor", m_Armor);
m_BlastResist = EditorGUILayout.FloatField("Blast Resistance", m_BlastResist);
m_MovementSpeed = EditorGUILayout.FloatField("Movement Speed", m_MovementSpeed);
m_HasActive = EditorGUILayout.BeginToggleGroup("Has this Item actives", m_HasActive);
m_MovementSpeed = EditorGUILayout.FloatField("Movement Speed", m_MovementSpeed);
EditorGUILayout.EndToggleGroup();
if (GUILayout.Button("Create Item", GUILayout.Width(100f)))
{
GameObject m_NewItem = new GameObject(m_ItemName);
m_NewItem.transform.parent = GameObject.FindGameObjectWithTag("ItemsParent").transform;
m_NewItem.AddComponent<CanvasRenderer>();
m_NewItem.AddComponent<Image>();
m_NewItem.AddComponent<Button>();
//m_NewItem.GetComponent<Button>().onClick.AddListener(() => GameObject.FindGameObjectWithTag("Store").GetComponent<StoreBehaviour>().SelectItem(m_NewItem));
//m_NewItem.GetComponent<Button>().onClick.(delegate {GameObject.FindGameObjectWithTag("Store").GetComponent<StoreBehaviour>().SelectItem(m_NewItem);});
// UnityAction action = new UnityAction(Func);
UnityAction m_Action;
// m_Action = new UnityAction(GetAction);
m_Action = new UnityAction(m_StoreBehaviour.Test);
UnityEventTools.AddPersistentListener(m_NewItem.GetComponent<Button>().onClick, m_Action);
m_NewItem.AddComponent<ItemStats>();
}
EditorGUILayout.EndScrollView();
}
void GetAction()
{
Debug.Log("Wat");
}
}
The error points me to line 27.
Now The window doesn’t even open it just gives me an error but the worst part is that the script works in a new project.
I tried many different things like reseting the editor layout changing the syntax of line 27 and 28 but nothing worked
Please help me guys I need to get this working
thanks in advance to the saviour xD,
skullbeats1