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 /
  • Help Room /
avatar image
0
Question by Alex-Gama · Apr 27, 2018 at 06:10 AM · unity 5multiplayerservergetcomponentclient

GetComponent for the client doesn't work properly in RPC calls or serverside calls?

So I've ended up getting into a pretty twisted and inefficient way of handling multiplayer shooting but it's kinda too late, I don't have enough time to redo it. I basically want to use a line renderer to draw a tracer for the raycasting shooting in our top down game.

The problem I have is that if the server completely handles the tracers then it looks off on the client since the client and server are out of sync. Instead I want to draw the tracer using client data for the client shooting and then use the server for everyone else.

Since the shooting is handled in the gunbase class which is attached to a gun (Which can't have a NetworkIdentity on it since the player already had one), I had to make a networked component called RenderTracer that handles the LineRenderer. Anyway, it was easy enough to make the clientside tracers but when I try to draw the server side tracers on all but the client, I've run into issues.

 public class RenderTracer : NetworkBehaviour
 {
     [SerializeField]
     private LineRenderer _tracer;
     [SerializeField]
     private Transform _firePoint;
     private ClientManager _clientMgr;
 
     private void Start()
     {
         _clientMgr = GameObject.Find("ClientManager").GetComponent<ClientManager>();
         _tracer = _firePoint.GetComponent<LineRenderer>();
     }
 
     public void RenderNewTracer(Vector3 hitPoint, GameObject gunOwner)
     {
         if (isLocalPlayer && !isServer)
         {
             Debug.Log("Not server");
             StartCoroutine("RenderTracerCoroutine", (hitPoint));
         }
         else
         {
             Debug.Log("Server");
             StartCoroutine("RenderTracerCoroutine", (hitPoint));
             Debug.Log("Gun owner: " + gunOwner.name);
 
             foreach (uint player in _clientMgr._playerIDs)
             {
                 GameObject playerGO = ClientScene.FindLocalObject(new NetworkInstanceId(player));
                 Debug.Log("Player: " + playerGO.name);
                 if (playerGO == gunOwner)
                 {
                     Debug.Log("Player shot: " + playerGO.name);
                     playerGO.GetComponent<RenderTracer>().RenderOtherTracer(hitPoint, gunOwner);
                 }
             }
         }
     }
 
     [ClientRpc]
     void RpcRenderTracer(Vector3 hitPoint, GameObject gunOwner)
     {
         Debug.Log("RPC");
         RenderOtherTracer(hitPoint, gunOwner);
     }
 
     void RenderOtherTracer(Vector3 hitPoint, GameObject gunOwner)
     {
         Debug.Log("RPC gameobject: " + this.gameObject.name);
         if (!isLocalPlayer)
         {
             return;
         }
 
         Debug.Log("!Local player");
         Debug.Log("Is " + this.gameObject.name + " owner of shot (" + gunOwner.name + "): " + (gunOwner == this.gameObject).ToString());
         if (gunOwner != this.gameObject)
         {
             Debug.Log("Zoop");
             StartCoroutine("RenderTracerCoroutine", (hitPoint));
         }
     }
 
     IEnumerator RenderTracerCoroutine(Vector3 hitPoint)
     {
         Debug.Log("Tracer drawn");
         _tracer.enabled = true;
         _tracer.SetPosition(0, _firePoint.position + (_firePoint.forward * 2));
         _tracer.SetPosition(1, _firePoint.position + hitPoint);
 
         yield return null;
         _tracer.enabled = false;
     }

Don't judge code too bad (Though any improvements would be appreciated) but that's the code I have for it. The problem comes on this line:

 playerGO.GetComponent<RenderTracer>().RenderOtherTracer(hitPoint, gunOwner);

The playerGO is correct and the line is only being called for that GameObject. Though even if the playerGO is not the server gameobject, the function RenderOtherTracer is still being called on the server. No matter what I do, I can't get the client component through server calls whether it's an RPC or direct like above. With RPCs if I call this.gameobject, it always gets the server's gameobject and not the clients one. Any ideas on why this doesn't work?

alt text

Example above is from the console of Player1 (Server). Why does Player1 see the Debug.Log("RPC gameobject: " + this.gameObject.name);that should only be seen by Player2? On Player 2 (The client), the RPC gameobject will be the server even though it should be itself.

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

0 Replies

· Add your reply
  • Sort: 

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

265 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 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 avatar image avatar image avatar image

Related Questions

What is difference between Network.InitializeServer and Unet. please help me 0 Answers

UNet Server-Client Command Functions Help 0 Answers

Networking best practices for handling local player 0 Answers

dedicated server 0 Answers

API for multiplayer game with authoritative server? 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