Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need Help With Error

Discussion in 'Scripting' started by Jackk_, Nov 18, 2017.

  1. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    49
    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
    Code (CSharp):
    1. using DarkRift;
    2. using System.Collections;
    3. using UnityEngine;
    4. using Yasil;
    5.  
    6. namespace Yasil.Player
    7. {
    8.     public class PlayerOthersManager : MonoBehaviour
    9.     {
    10.         private Player _myPlayer;
    11.  
    12.         private void Start()
    13.         {
    14.             _myPlayer = GameObject.Find("Player").GetComponent<Player>();
    15.  
    16.             DarkRiftAPI.onDataDetailed += RecieveData;
    17.             DarkRiftAPI.onPlayDisconnected += PlayerDisconnect;
    18.             Player.onMyUmaReady += SendIamNew;
    19.         }
    20.  
    21.         private void SendIamNew()
    22.         {
    23.             if (DarkRiftAPI.isConnected)
    24.             {
    25.                 DarkRiftAPI.SendMessageToOthers(NT.StartT, NT.StartS.JoinGame, "HI JACK");
    26.  
    27.                 using (DarkRiftWriter writer = new DarkRiftWriter())
    28.                 {
    29.                     writer.Write(_myPlayer.UserID);
    30.                     writer.Write(_myPlayer.PlayerName);
    31.                     writer.Write(_myPlayer.PlayerGender);
    32.                     writer.Write(_myPlayer.PlayerRace);
    33.                     writer.Write(_myPlayer.GetUMARecipe());
    34.                     DarkRiftAPI.SendMessageToOthers(NT.StartT, NT.StartS.Spawn, writer);
    35.                 }
    36.             }
    37.         }
    38.  
    39.         private void RecieveData(ushort senderID, byte tag, ushort subject, object data)
    40.         {
    41.             if (tag == NT.StartT)
    42.             {
    43.                 if (subject == NT.StartS.JoinGame)
    44.                 {
    45.                     using (DarkRiftWriter writer = new DarkRiftWriter())
    46.                     {
    47.                         writer.Write(_myPlayer.UserID);
    48.                         writer.Write(_myPlayer.PlayerName);
    49.                         writer.Write(_myPlayer.PlayerGender);
    50.                         writer.Write(_myPlayer.PlayerRace);
    51.                         writer.Write(_myPlayer.GetUMARecipe());
    52.                         DarkRiftAPI.SendMessageToID(senderID, NT.StartT, NT.StartS.Spawn, writer);
    53.                     }
    54.                 }
    55.  
    56.                 if (subject == NT.StartS.Spawn)
    57.                 {
    58.                     using (DarkRiftReader reader = (DarkRiftReader)data)
    59.                     {
    60.                         int _id = reader.ReadInt32();
    61.                         string _playername = reader.ReadString();
    62.                         string _playergender = reader.ReadString();
    63.                         string _playerrace = reader.ReadString();
    64.                         string _umadata = reader.ReadString();
    65.  
    66.                         BuildOther(senderID, _id, _playername, _playergender, _playerrace, PlayerManager.Decompress(_umadata));
    67.                     }
    68.                 }
    69.             }
    70.         }
    71.  
    72.         private void BuildOther(int _senderID, int _id, string _playername, string _playergender, string _playerrace, byte[] _umadata)
    73.         {
    74.             GameObject GO = new GameObject("Player-" + _senderID.ToString());
    75.             PlayerOthers PO = GO.AddComponent<PlayerOthers>();
    76.             PO.MakePlayer(_senderID, _id, _playername, _playergender, _playerrace, _umadata);
    77.         }
    78.  
    79.         private void PlayerDisconnected(ushort ID)
    80.         {
    81.             GameObject GO = GameObject.Find("Player-" + ID.ToString());
    82.             Debug.Log(ID.ToString());
    83.  
    84.             Destroy(GO, 0.1f);
    85.         }
    86.     }
    87. }
    88.  
    Other files that may have some relevance
    PlayerOthers.cs
    Code (CSharp):
    1. using System;
    2. using UMA;
    3. using UnityEngine;
    4. using Yasil;
    5. using Yasil.Player;
    6. using DarkRift;
    7.  
    8. namespace Yasil.Player
    9. {
    10.     public class PlayerOthers : MonoBehaviour
    11.     {
    12.         #region Public Variables
    13.  
    14.         public RuntimeAnimatorController _animController;
    15.  
    16.         #endregion Public Variables
    17.  
    18.         #region Privates Variables
    19.  
    20.         //: TODO make an Player Class
    21.         [SerializeField]
    22.         private int userID;
    23.  
    24.         [SerializeField]
    25.         private string playerName;
    26.  
    27.         [SerializeField]
    28.         private string playerGender;
    29.  
    30.         [SerializeField]
    31.         private string playerRace;
    32.  
    33.         [SerializeField]
    34.         private int networkID;
    35.  
    36.         private UMADynamicAvatar _myumaDynamicAvatar;
    37.         private UMAData _myumaData;
    38.         private UMADnaHumanoid _umaDNA;
    39.         private UMADnaTutorial _umaTutorialDNA;
    40.         private UMAContext umaContext;
    41.         private UMAGenerator umaGenerator;
    42.  
    43.         private int _numberOfSlots = 40;
    44.  
    45.         #endregion Privates Variables
    46.  
    47.         #region Getter Setters
    48.  
    49.         public int NetworkID { get { return networkID; } private set { networkID = value; } }
    50.  
    51.         public int UserID { get { return userID; } private set { userID = value; } }
    52.  
    53.         public string PlayerName { get { return playerName; } private set { playerName = value; } }
    54.  
    55.         public string PlayerGender { get { return playerGender; } private set { playerGender = value; } }
    56.  
    57.         public string PlayerRace { get { return playerGender; } private set { playerRace = value; } }
    58.  
    59.         #endregion Getter Setters
    60.  
    61.  
    62.         private void Awake()
    63.         {
    64.             umaGenerator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>();
    65.             umaContext = GameObject.Find("UMAContext").GetComponent<UMAContext>();
    66.         }
    67.  
    68.         private void Start()
    69.         {
    70.             _animController = GameObject.Find("Player").GetComponent<Player>()._animController;
    71.         }
    72.  
    73.         private void OnApplicationQuit()
    74.         {
    75.            
    76.         }
    77.  
    78.    
    79.  
    80.         public void MakePlayer(int _senderID, int _userID, string _playername, string _playergender, string _playerrace, byte[] _umadata)
    81.         {
    82.             UserID = _userID;
    83.             PlayerName = _playername;
    84.             PlayerGender = _playergender;
    85.             PlayerRace = _playerrace;
    86.             NetworkID = _senderID;
    87.             MakeUMA(_umadata);
    88.  
    89.         }
    90.  
    91.         private void MakeUMA(byte[] _umarecipe)
    92.         {
    93.             GameObject GO = GameObject.Find("Player" + NetworkID.ToString());
    94.             GO.transform.parent = this.transform;
    95.             _myumaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();
    96.             _myumaDynamicAvatar.Initialize();
    97.             _myumaData = _myumaDynamicAvatar.umaData;
    98.             _myumaDynamicAvatar.umaGenerator = umaGenerator;
    99.             _myumaData.umaGenerator = umaGenerator;
    100.             _myumaData.umaRecipe.slotDataList = new SlotData[_numberOfSlots];
    101.             _umaDNA = new UMADnaHumanoid();
    102.             _umaTutorialDNA = new UMADnaTutorial();
    103.             _myumaData.umaRecipe.AddDna(_umaDNA);
    104.             _myumaData.umaRecipe.AddDna(_umaTutorialDNA);
    105.  
    106.             UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
    107.             recipe.SetBytes(_umarecipe);
    108.             _myumaDynamicAvatar.Load(recipe);
    109.             Destroy(recipe);
    110.             _myumaDynamicAvatar.animationController = _animController;
    111.             _myumaDynamicAvatar.UpdateNewRace();
    112.         }
    113.     }
    114. }
    Player.cs
    Code (CSharp):
    1. using System.Collections;
    2. using UMA;
    3. using UnityEngine;
    4. using Yasil;
    5. using Yasil.Player;
    6.  
    7. public class Player : MonoBehaviour
    8. {
    9.     #region Public Variables
    10.  
    11.     public RuntimeAnimatorController _animController;
    12.  
    13.     #endregion Public Variables
    14.  
    15.     #region Privates Variables
    16.  
    17.     //: TODO make an Player Class
    18.     [SerializeField]
    19.     private int userID;
    20.  
    21.     [SerializeField]
    22.     private string playerName;
    23.  
    24.     [SerializeField]
    25.     private string playerGender;
    26.  
    27.     [SerializeField]
    28.     private string playerRace;
    29.  
    30.     private UMADynamicAvatar _myumaDynamicAvatar;
    31.     private UMAData _myumaData;
    32.     private UMADnaHumanoid _umaDNA;
    33.     private UMADnaTutorial _umaTutorialDNA;
    34.     private UMAContext umaContext;
    35.     private UMAGenerator umaGenerator;
    36.  
    37.     private int _numberOfSlots = 40;
    38.  
    39.     #endregion Privates Variables
    40.  
    41.     #region Getter Setters
    42.  
    43.     //public int NetworkID { get { return networkID; } private set { networkID = value; } }
    44.  
    45.     public int UserID { get { return userID; } private set { userID = value; } }
    46.  
    47.     public string PlayerName { get { return playerName; } private set { playerName = value; } }
    48.  
    49.     public string PlayerGender { get { return playerGender; } private set { playerGender = value; } }
    50.  
    51.     public string PlayerRace { get { return playerGender; } private set { playerRace = value; } }
    52.  
    53.     #endregion Getter Setters
    54.  
    55.     #region Delegates
    56.  
    57.     public delegate void MyUmaReadyEventHandler();
    58.  
    59.     #endregion Delegates
    60.  
    61.     #region Events
    62.  
    63.     public static event MyUmaReadyEventHandler onMyUmaReady;
    64.  
    65.     #endregion Events
    66.  
    67.     private void Awake()
    68.     {
    69.         umaGenerator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>();
    70.         umaContext = GameObject.Find("UMAContext").GetComponent<UMAContext>();
    71.     }
    72.  
    73.     private void Start()
    74.     {
    75.         PlayerManager.onPlayerLoadOK += MakePlayer;
    76.         PlayerManager.LoadPlayer();
    77.     }
    78.  
    79.     private void OnApplicationQuit()
    80.     {
    81.         PlayerManager.onPlayerLoadOK -= MakePlayer;
    82.     }
    83.  
    84.     private string GetUMARecipe()
    85.     {
    86.         byte[] _myplayerbytes;
    87.  
    88.         UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
    89.         recipe.Save(_myumaDynamicAvatar.umaData.umaRecipe, umaContext);
    90.         _myplayerbytes = recipe.GetBytes();
    91.         return PlayerManager.Compress(_myplayerbytes);
    92.     }
    93.  
    94.     private void SaveMyPlayer()
    95.     {
    96.         PlayerManager.SavePlayer(userID, playerName, playerRace, playerGender, GetUMARecipe());
    97.     }
    98.  
    99.     public void MakePlayer(int _userID, string _playername, string _playergender, string _playerrace, byte[] _umadata)
    100.     {
    101.         UserID = _userID;
    102.         PlayerName = _playername;
    103.         PlayerGender = _playergender;
    104.         PlayerRace = _playerrace;
    105.         MakeUMA(_umadata);
    106.  
    107.         if (onMyUmaReady != null)
    108.             onMyUmaReady();
    109.     }
    110.  
    111.     private void MakeUMA(byte[] _umarecipe)
    112.     {
    113.         GameObject GO = GameObject.Find("Player");
    114.         GO.transform.parent = this.transform;
    115.         _myumaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();
    116.         _myumaDynamicAvatar.Initialize();
    117.         _myumaData = _myumaDynamicAvatar.umaData;
    118.         _myumaDynamicAvatar.umaGenerator = umaGenerator;
    119.         _myumaData.umaGenerator = umaGenerator;
    120.         _myumaData.umaRecipe.slotDataList = new SlotData[_numberOfSlots];
    121.         _umaDNA = new UMADnaHumanoid();
    122.         _umaTutorialDNA = new UMADnaTutorial();
    123.         _myumaData.umaRecipe.AddDna(_umaDNA);
    124.         _myumaData.umaRecipe.AddDna(_umaTutorialDNA);
    125.  
    126.         UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
    127.         recipe.SetBytes(_umarecipe);
    128.         _myumaDynamicAvatar.Load(recipe);
    129.         Destroy(recipe);
    130.         _myumaDynamicAvatar.animationController = _animController;
    131.         _myumaDynamicAvatar.UpdateNewRace();
    132.     }
    133. }
    If anyone could please help me with this error then I'd greatly appreciate it :)
     
  2. whileBreak

    whileBreak

    Joined:
    Aug 28, 2014
    Posts:
    289
    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.
    Code (CSharp):
    1. private Root.Player _myPlayer;
    If that doesn't work create your own namespace
    Code (CSharp):
    1. namespace MySpace{
    2.  
    3. public class Player : MonoBehaviour
    4. {
    5.  
    6. ////All code
    7.  
    8. }
    9. }
    Code (CSharp):
    1. private MySpace.Player _myPlayer;
     
  3. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    49
    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
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    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:

    Code (CSharp):
    1. namespace Yasil.Player
    2. {
    3.     public class Player : MonoBehaviour
    4.     {
    5.         //...
    6.     }
    7. }
    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.
     
    Last edited: Nov 19, 2017
    whileBreak likes this.
  5. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    49
    Thank you!
     
  6. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    49
    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 :/
     
  7. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    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. :/
     
  8. Jackk_

    Jackk_

    Joined:
    May 2, 2017
    Posts:
    49
    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! :)

    This is my Hierarchy when I log into the game successfully