Forum begins after the advertisement:
[General] Build Error – The type or namespace name ‘Editor’ could not be found
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [General] Build Error – The type or namespace name ‘Editor’ could not be found
- This topic has 2 replies, 3 voices, and was last updated 3 weeks, 6 days ago by Alp Apustaja.
-
AuthorPosts
-
December 25, 2024 at 1:51 am #16904::
Hello Terence! I’ve got an issue. Could you help me to resolve it?
When I trying to compilate the game I getting an errors
Assets\Scripts\Weapons\WeaponDataEditor.cs(8,33): error CS0246: The type or namespace name ‘Editor’ could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Weapons\WeaponDataEditor.cs(6,2): error CS0246: The type or namespace name ‘CustomEditorAttribute’ could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Weapons\WeaponDataEditor.cs(6,2): error CS0246: The type or namespace name ‘CustomEditor’ could not be found (are you missing a using directive or an assembly reference?)
using UnityEditor; using System; using System.Linq; using System.Collections.Generic; [CustomEditor(typeof(WeaponData))] public class WeaponDataEditor : Editor { WeaponData weaponData; string[] weaponSubtypes; int selectedWeaponSubtype; void OnEnable() { // Cache the weapon data value weaponData = (WeaponData)target; //Retrive all the weapon subtypes and cache it System.Type baseType = typeof(Weapon); List<System.Type> subTypes = System.AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => baseType.IsAssignableFrom(p) && p != baseType) .ToList(); //Add a none option on front List<string> subTypesString = subTypes.Select(t => t.Name).ToList(); subTypesString.Insert(0, "None"); weaponSubtypes = subTypesString.ToArray(); //Ensure that we are using the correct weapon subtype selectedWeaponSubtype = Math.Max(0, Array.IndexOf(weaponSubtypes, weaponData.behaviour)); } public override void OnInspectorGUI() { //Draw a dropdown in the Inspector selectedWeaponSubtype = EditorGUILayout.Popup("Behaviour", Math.Max(0, selectedWeaponSubtype), weaponSubtypes); if (selectedWeaponSubtype > 0) { //Updates the behaviour field weaponData.behaviour = weaponSubtypes[selectedWeaponSubtype].ToString(); EditorUtility.SetDirty(weaponData); //Marks the object to save DrawDefaultInspector(); //Draw the default inspector elements } } }
December 25, 2024 at 2:12 am #16905::Hello, ZBeast!
It looks like you are encountering errors related to namespaces and types when trying to compile your game. The errors specifically mention that the ‘Editor’ type, ‘CustomEditorAttribute’ type, and ‘CustomEditor’ type could not be found.
To resolve these issues, you need to make sure you have the correct using directives and assembly references in your script. In this case, since you are working with Unity and trying to create a custom editor script, you need to ensure that you have the proper references.
Here are some steps you can take to resolve the issues:
- Add the following using directive at the
December 25, 2024 at 1:57 pm #16907December 26, 2024 at 1:13 am #16909December 26, 2024 at 2:11 am #16910::You’re welcome, ZBeast! If you have any more questions or need further assistance, feel free to ask. Happy coding!
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: