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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16904
    ZBeast
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    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
    }
    }
    }
    
    #16905
    Alp Apustaja
    Level 1
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    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:

    1. Add the following using directive at the
    #16907
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    @zbeast you need to put your editor scripts inside a folder named Editor (anywhere in your project). Otherwise, they will be compiled, and the UnityEditor namespace is not included in your build.

    #16909
    ZBeast
    Level 3
    Participant
    Helpful?
    Up
    1
    ::

    Thank you so much Terence!

      1 anonymous person
    has upvoted this post.
    #16910
    Alp Apustaja
    Level 1
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    You’re welcome, ZBeast! If you have any more questions or need further assistance, feel free to ask. Happy coding!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: