Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 maturski · Aug 16, 2018 at 01:07 AM · networkingmultiplayermultiplayer-networking

Why is playerControllerId = -1

I thought Local Player has playerControllerId = 0 - Why am I displaying -1


alt text

screenshot-2018-08-15-210310.png (26.7 kB)
Comment
Add comment · Show 1
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 Piyush_Pandey · Aug 16, 2018 at 09:24 AM 0
Share

please share your code here.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by maturski · Aug 16, 2018 at 10:33 AM

Line 94 -- Just debugging and trying to find out why the camera isn't setting the target as the latest player to spawn

 using System;
 using UnityEngine;
 using UnityEngine.Networking;
 
 namespace UnityStandardAssets.Cameras
 {
     public abstract class AbstractTargetFollower : NetworkBehaviour
     {
         public enum UpdateType // The available methods of updating are:
         {
             FixedUpdate, // Update in FixedUpdate (for tracking rigidbodies).
             LateUpdate, // Update in LateUpdate. (for tracking objects that are moved in Update)
             ManualUpdate, // user must call to update camera
         }
 
         [SerializeField] protected Transform m_Target;            // The target object to follow
         [SerializeField] private bool m_AutoTargetPlayer = true;  // Whether the rig should automatically target the player.
         [SerializeField] private UpdateType m_UpdateType;         // stores the selected update type
 
         protected Rigidbody targetRigidbody;
 
 
         protected virtual void Start()
         {
 
                 // if auto targeting is used, find the object tagged "Player"
                 // any class inheriting from this should call base.Start() to perform this action!
                 if (m_AutoTargetPlayer)
                 {
                     FindAndTargetPlayer();
                 }
                 if (m_Target == null) return;
                 targetRigidbody = m_Target.GetComponent<Rigidbody>();
 
         }
 
 
         private void FixedUpdate()
         {
 
                 // we update from here if updatetype is set to Fixed, or in auto mode,
                 // if the target has a rigidbody, and isn't kinematic.
                 if (m_AutoTargetPlayer && (m_Target == null || !m_Target.gameObject.activeSelf))
                 {
                     FindAndTargetPlayer();
                 }
                 if (m_UpdateType == UpdateType.FixedUpdate)
                 {
                     FollowTarget(Time.deltaTime);
                 }
         }
 
 
         private void LateUpdate()
         {
 
                 // we update from here if updatetype is set to Late, or in auto mode,
                 // if the target does not have a rigidbody, or - does have a rigidbody but is set to kinematic.
                 if (m_AutoTargetPlayer && (m_Target == null || !m_Target.gameObject.activeSelf))
                 {
                     FindAndTargetPlayer();
                 }
                 if (m_UpdateType == UpdateType.LateUpdate)
                 {
                     FollowTarget(Time.deltaTime);
                 }
 
         }
 
 
         public void ManualUpdate()
         {
 
                 // we update from here if updatetype is set to Late, or in auto mode,
                 // if the target does not have a rigidbody, or - does have a rigidbody but is set to kinematic.
                 if (m_AutoTargetPlayer && (m_Target == null || !m_Target.gameObject.activeSelf))
                 {
                     FindAndTargetPlayer();
                 }
                 if (m_UpdateType == UpdateType.ManualUpdate)
                 {
                     FollowTarget(Time.deltaTime);
                 }
 
         }
 
         protected abstract void FollowTarget(float deltaTime);
 
 
         public void FindAndTargetPlayer()
         {
             
             if (this.isLocalPlayer) {
                 Debug.Log("playerControllerId = " + playerControllerId);
             }
 
             var targetObj = GameObject.FindGameObjectWithTag("Player");
 
             if (targetObj)
             {
                 //SetTarget(targetObj.transform);
                 SetTarget(targetObj.transform);
             }
 
         }
 
 
         public virtual void SetTarget(Transform newTransform)
         {
             m_Target = newTransform;
         }
 
 
         public Transform Target
         {
             
             get { return m_Target; }
         }
 
     }
 }
 
Comment
Add comment · 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
0

Answer by PhoenixFeng · Sep 24, 2018 at 11:18 AM

If a client didn't add any player, the NetworkBehaviour.playerControllerId is -1 as default .(Yes, the default value of playerControllerId is -1, not 0. You can try not adding a player when you connect to the server and print(playerControllerId) to check this.)

If you have ever used ClientScene.AddPlayer(short playerControllerId) to spawn a new player for the client, the playerControllerId shouldn't be -1.

How did you spawn your Player? Or have you ever removed the player? Or you just didn't add one?

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

131 People are following this question.

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

Related Questions

Unity networking tutorial? 6 Answers

UNet - Connecting and Testing a 'choose your character' scenario 0 Answers

Best way to choose Google Play Realtime Multiplayer Host? 0 Answers

Network command is running on client? 1 Answer

Unet: Discern between user disconnection and connection lost 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges