Need Help With Error

The Error: CS0118: ‘Yasil.Player’ is a ‘namespace’ but a ‘type’ was expected.

I am following Yasil’s Tutorials on making an MMO, and on his episode he writes down this code which seems to work perfectly fine for him (around 5 minutes in you can see it) but is giving me this error at Line 10 of PlayerOthersManager.cs

Main File Involved
PlayerOthersManager.cs

using DarkRift;
using System.Collections;
using UnityEngine;
using Yasil;

namespace Yasil.Player
{
    public class PlayerOthersManager : MonoBehaviour
    {
        private Player _myPlayer;

        private void Start()
        {
            _myPlayer = GameObject.Find("Player").GetComponent<Player>();

            DarkRiftAPI.onDataDetailed += RecieveData;
            DarkRiftAPI.onPlayDisconnected += PlayerDisconnect;
            Player.onMyUmaReady += SendIamNew;
        }

        private void SendIamNew()
        {
            if (DarkRiftAPI.isConnected)
            {
                DarkRiftAPI.SendMessageToOthers(NT.StartT, NT.StartS.JoinGame, "HI JACK");

                using (DarkRiftWriter writer = new DarkRiftWriter())
                {
                    writer.Write(_myPlayer.UserID);
                    writer.Write(_myPlayer.PlayerName);
                    writer.Write(_myPlayer.PlayerGender);
                    writer.Write(_myPlayer.PlayerRace);
                    writer.Write(_myPlayer.GetUMARecipe());
                    DarkRiftAPI.SendMessageToOthers(NT.StartT, NT.StartS.Spawn, writer);
                }
            }
        }

        private void RecieveData(ushort senderID, byte tag, ushort subject, object data)
        {
            if (tag == NT.StartT)
            {
                if (subject == NT.StartS.JoinGame)
                {
                    using (DarkRiftWriter writer = new DarkRiftWriter())
                    {
                        writer.Write(_myPlayer.UserID);
                        writer.Write(_myPlayer.PlayerName);
                        writer.Write(_myPlayer.PlayerGender);
                        writer.Write(_myPlayer.PlayerRace);
                        writer.Write(_myPlayer.GetUMARecipe());
                        DarkRiftAPI.SendMessageToID(senderID, NT.StartT, NT.StartS.Spawn, writer);
                    }
                }

                if (subject == NT.StartS.Spawn)
                {
                    using (DarkRiftReader reader = (DarkRiftReader)data)
                    {
                        int _id = reader.ReadInt32();
                        string _playername = reader.ReadString();
                        string _playergender = reader.ReadString();
                        string _playerrace = reader.ReadString();
                        string _umadata = reader.ReadString();

                        BuildOther(senderID, _id, _playername, _playergender, _playerrace, PlayerManager.Decompress(_umadata));
                    }
                }
            }
        }

        private void BuildOther(int _senderID, int _id, string _playername, string _playergender, string _playerrace, byte[] _umadata)
        {
            GameObject GO = new GameObject("Player-" + _senderID.ToString());
            PlayerOthers PO = GO.AddComponent<PlayerOthers>();
            PO.MakePlayer(_senderID, _id, _playername, _playergender, _playerrace, _umadata);
        }

        private void PlayerDisconnected(ushort ID)
        {
            GameObject GO = GameObject.Find("Player-" + ID.ToString());
            Debug.Log(ID.ToString());

            Destroy(GO, 0.1f);
        }
    }
}

Other files that may have some relevance
PlayerOthers.cs

using System;
using UMA;
using UnityEngine;
using Yasil;
using Yasil.Player;
using DarkRift;

namespace Yasil.Player
{
    public class PlayerOthers : MonoBehaviour
    {
        #region Public Variables

        public RuntimeAnimatorController _animController;

        #endregion Public Variables

        #region Privates Variables

        //: TODO make an Player Class
        [SerializeField]
        private int userID;

        [SerializeField]
        private string playerName;

        [SerializeField]
        private string playerGender;

        [SerializeField]
        private string playerRace;

        [SerializeField]
        private int networkID;

        private UMADynamicAvatar _myumaDynamicAvatar;
        private UMAData _myumaData;
        private UMADnaHumanoid _umaDNA;
        private UMADnaTutorial _umaTutorialDNA;
        private UMAContext umaContext;
        private UMAGenerator umaGenerator;

        private int _numberOfSlots = 40;

        #endregion Privates Variables

        #region Getter Setters

        public int NetworkID { get { return networkID; } private set { networkID = value; } }

        public int UserID { get { return userID; } private set { userID = value; } }

        public string PlayerName { get { return playerName; } private set { playerName = value; } }

        public string PlayerGender { get { return playerGender; } private set { playerGender = value; } }

        public string PlayerRace { get { return playerGender; } private set { playerRace = value; } }

        #endregion Getter Setters


        private void Awake()
        {
            umaGenerator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>();
            umaContext = GameObject.Find("UMAContext").GetComponent<UMAContext>();
        }

        private void Start()
        {
            _animController = GameObject.Find("Player").GetComponent<Player>()._animController;
        }

        private void OnApplicationQuit()
        {
           
        }

    

        public void MakePlayer(int _senderID, int _userID, string _playername, string _playergender, string _playerrace, byte[] _umadata)
        {
            UserID = _userID;
            PlayerName = _playername;
            PlayerGender = _playergender;
            PlayerRace = _playerrace;
            NetworkID = _senderID;
            MakeUMA(_umadata);

        }

        private void MakeUMA(byte[] _umarecipe)
        {
            GameObject GO = GameObject.Find("Player" + NetworkID.ToString());
            GO.transform.parent = this.transform;
            _myumaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();
            _myumaDynamicAvatar.Initialize();
            _myumaData = _myumaDynamicAvatar.umaData;
            _myumaDynamicAvatar.umaGenerator = umaGenerator;
            _myumaData.umaGenerator = umaGenerator;
            _myumaData.umaRecipe.slotDataList = new SlotData[_numberOfSlots];
            _umaDNA = new UMADnaHumanoid();
            _umaTutorialDNA = new UMADnaTutorial();
            _myumaData.umaRecipe.AddDna(_umaDNA);
            _myumaData.umaRecipe.AddDna(_umaTutorialDNA);

            UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
            recipe.SetBytes(_umarecipe);
            _myumaDynamicAvatar.Load(recipe);
            Destroy(recipe);
            _myumaDynamicAvatar.animationController = _animController;
            _myumaDynamicAvatar.UpdateNewRace();
        }
    }
}

Player.cs

using System.Collections;
using UMA;
using UnityEngine;
using Yasil;
using Yasil.Player;

public class Player : MonoBehaviour
{
    #region Public Variables

    public RuntimeAnimatorController _animController;

    #endregion Public Variables

    #region Privates Variables

    //: TODO make an Player Class
    [SerializeField]
    private int userID;

    [SerializeField]
    private string playerName;

    [SerializeField]
    private string playerGender;

    [SerializeField]
    private string playerRace;

    private UMADynamicAvatar _myumaDynamicAvatar;
    private UMAData _myumaData;
    private UMADnaHumanoid _umaDNA;
    private UMADnaTutorial _umaTutorialDNA;
    private UMAContext umaContext;
    private UMAGenerator umaGenerator;

    private int _numberOfSlots = 40;

    #endregion Privates Variables

    #region Getter Setters

    //public int NetworkID { get { return networkID; } private set { networkID = value; } }

    public int UserID { get { return userID; } private set { userID = value; } }

    public string PlayerName { get { return playerName; } private set { playerName = value; } }

    public string PlayerGender { get { return playerGender; } private set { playerGender = value; } }

    public string PlayerRace { get { return playerGender; } private set { playerRace = value; } }

    #endregion Getter Setters

    #region Delegates

    public delegate void MyUmaReadyEventHandler();

    #endregion Delegates

    #region Events

    public static event MyUmaReadyEventHandler onMyUmaReady;

    #endregion Events

    private void Awake()
    {
        umaGenerator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>();
        umaContext = GameObject.Find("UMAContext").GetComponent<UMAContext>();
    }

    private void Start()
    {
        PlayerManager.onPlayerLoadOK += MakePlayer;
        PlayerManager.LoadPlayer();
    }

    private void OnApplicationQuit()
    {
        PlayerManager.onPlayerLoadOK -= MakePlayer;
    }

    private string GetUMARecipe()
    {
        byte[] _myplayerbytes;

        UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
        recipe.Save(_myumaDynamicAvatar.umaData.umaRecipe, umaContext);
        _myplayerbytes = recipe.GetBytes();
        return PlayerManager.Compress(_myplayerbytes);
    }

    private void SaveMyPlayer()
    {
        PlayerManager.SavePlayer(userID, playerName, playerRace, playerGender, GetUMARecipe());
    }

    public void MakePlayer(int _userID, string _playername, string _playergender, string _playerrace, byte[] _umadata)
    {
        UserID = _userID;
        PlayerName = _playername;
        PlayerGender = _playergender;
        PlayerRace = _playerrace;
        MakeUMA(_umadata);

        if (onMyUmaReady != null)
            onMyUmaReady();
    }

    private void MakeUMA(byte[] _umarecipe)
    {
        GameObject GO = GameObject.Find("Player");
        GO.transform.parent = this.transform;
        _myumaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();
        _myumaDynamicAvatar.Initialize();
        _myumaData = _myumaDynamicAvatar.umaData;
        _myumaDynamicAvatar.umaGenerator = umaGenerator;
        _myumaData.umaGenerator = umaGenerator;
        _myumaData.umaRecipe.slotDataList = new SlotData[_numberOfSlots];
        _umaDNA = new UMADnaHumanoid();
        _umaTutorialDNA = new UMADnaTutorial();
        _myumaData.umaRecipe.AddDna(_umaDNA);
        _myumaData.umaRecipe.AddDna(_umaTutorialDNA);

        UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
        recipe.SetBytes(_umarecipe);
        _myumaDynamicAvatar.Load(recipe);
        Destroy(recipe);
        _myumaDynamicAvatar.animationController = _animController;
        _myumaDynamicAvatar.UpdateNewRace();
    }
}

If anyone could please help me with this error then I’d greatly appreciate it :slight_smile:

The compiler is getting confused with Yasil.Player namespace and Player class, either change the namespace name or the class name or specify explicitly from where you are getting player. I don’t know what the default namespace is for all scripts but i think its root.

private Root.Player _myPlayer;

If that doesn’t work create your own namespace

namespace MySpace{

public class Player : MonoBehaviour
{

////All code

}
}
private MySpace.Player _myPlayer;

I tried all three methods you listed and it gives me loads of errors, I don’t understand why Yasil can do it in his tutorial but I can’t when the code I use is the same

The error appears because the namespace itself (Yasil.Player) has higher priority within itself than the globally defined class which is also named Player. (The global namespace is global:: btw, but you won’t see that very often).

So the first suggestion could work if you used global:: in front of Player, but that’s not very common.
The second however, should work. In that case though, you’d either always need to use the FQN (full qualified name), i.e. MyNamespace.Player (MyNamespace can be changed to something different if you want) or tell your other scripts about that namespace using a directive at the top, ie. using MyNamespace;.

This being said, I took the time and checked the tutorial and as expected, he also put the Player class into the Yasil.Player namespace. So in order to stay consistent with the tutorial:

namespace Yasil.Player
{
    public class Player : MonoBehaviour
    {
        //...
    }
}

This works as the Player class is now inside the Yasil.Player namespace, hence the it’s prioritized within the namespace.

You probably just missed that one.
Other options would be to use an alias name for the player class, but since you do the tutorial, just add the missing namespace.

*edit Sorry, I fixed that silly font-bug.

1 Like

Thank you!

However now, if you look towards the end of Yasil’s video you can see that his player 2 is entered in the game when he logs in and now mine doesn’t and there are no errors or anything :confused:

Unfortunately I cannot help with that, as this could have a lot of reasons and tracking this down would actually require going through the complete tutorial + creating a check-list for every relevant thing… that would take a lot of time, and the list would probably not be very short either.

You may either try to isolate the issue, hope for someone that’s got the time to look into it or someone who has even completed this tutorial successfully… Or you could just try to contact the owner of the channel and ask for help, as he surely knows the code best.

If I saw that correctly, he even uses custom networking and some other libs, so it’s even gonna be more difficult to find someone who’s gonna take the time and look into it.

Sorry for that. :confused:

I think the DontDestroyOnLoad is preventing the second player from being added to the scene, as 18:43 of his video it shows his game playing without this file in the hierarchy. If you could let me know how to remove this then that’d be great! :slight_smile:

This is my Hierarchy when I log into the game successfully