• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TwoTen · Jun 13, 2016 at 06:06 AM · networkingplayercontrollermanagerlobby

Cannot Convert type UnityEngine.Networking.PlayerController to PlayerController

So i'm using the Lobby Manager that is on the asset store by Unity. And in the lobbymanager.cs script there is a problem that just occured to me. it's not been there before and i dont know whats causing it. The error is in the title. And it's about this peice of code:

   //allow to handle the (+) button to add/remove player
     public void OnPlayersNumberModified(int count)
     {
         _playerNumber += count;
 
         int localPlayerCount = 0;
         foreach (PlayerController p in ClientScene.localPlayers)
             localPlayerCount += (p == null || p.playerControllerId == -1) ? 0 : 1;
 
         addPlayerButton.SetActive(localPlayerCount < maxPlayersPerConnection && _playerNumber < maxPlayers);
     }


My project is kindoff on hold atm because if this wich sucks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Waka-Takaki · Jun 13, 2016 at 07:10 AM

Your error is telling you that you're trying to convert Unity.Networking.PlayerController to a different type called PlayerController.

Have you got another script called PlayerController in your project, aside from the one in unity networking?

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TwoTen · Jun 13, 2016 at 08:57 AM 0
Share

....... That was the issue. There is another script I added called PlayerController. Creds to you man. I appreciate that.

avatar image Datapax · Dec 19, 2016 at 02:01 PM 0
Share

So, we can't name our script PlayerController if we a re using the Lobby asset right?

Long live "Find and Replace" : )

avatar image Hellium Datapax · Dec 19, 2016 at 02:06 PM 1
Share

Yes you can, but you have to declare it in your own namespace

avatar image Bunny83 Hellium · Dec 19, 2016 at 04:00 PM 1
Share

... or if you declare it in the global namespace you always have to use UnityEngine.Networking.PlayerController whenever you need to use Unity's "PlayerController" class.

However it's best to not use a name that is already used by another script / component. You still might run into issues. While AddComponent with a string argument has been deprecated, GetComponent still exists in the string version. So having two component classes with the same name still might cause problems, even when you use namespaces.

Though in the case of "PlayerController" it shouldn't be an issue since PlayerController is not a component ^^.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer

Player Prefab on Lobby Managers? 5 Answers

UNET Players not spawning on server change scene 1 Answer

How to get local players? 1 Answer

On NetworkLobbyManager override, base.OnLobbyServerCreate[Lobby/Game]Player() return null. Is that normal ? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges