Search Unity

RPC problem

Discussion in 'Multiplayer' started by Fegloy, Mar 20, 2013.

  1. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    RPC calling:

    networkView.RPC("Spawn",RPCMode.AllBuffered...

    RPC function:

    [RPC]
    private void Spawn(...)
    {
    }

    Problem is that when other player join to game. Then becomes an error that says that "Spawn" doesn't exist in a other script that haves [RPC] functions too.
    Both have Network view on them.

    THIS ALREADY SOLVED NEW PROBLEM BELOW
     
    Last edited: Apr 2, 2013
  2. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    Are you using unity networking?
     
  3. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    Network.InitializeServer and MasterServer.
    If you mean that.
     
  4. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    OK, give us a bit more code here please. It is hard to tell what is going wrong when you just post a partial of your code.

    *Just a note, when asking for help; it is better to give too much information than not enough
     
  5. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    The method must reside on the same GameObject where it is called.
     
  6. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Isn't it @RPC for unitys network and [RPC] in Photon?
     
  7. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Nope, it's [RPC] for C#
     
  8. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
  9. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    Here is more code:

    It begins like this:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerSync : MonoBehaviour {
    RPC call:

    Code (csharp):
    1. if (GUI.Button(new Rect(0,0,80,20),"Button"))
    2.  
    3. {
    4. networkView.RPC("Spawn",RPCMode.AllBuffered,unitselected,public_player_position,value1);
    5.  
    6. }
    Method in same code:
    Code (csharp):
    1. [RPC]
    2.     private void Spawn(int unitselected2,Vector3 location,int value)
    3.     {
    4.         ...
    5. }
    ERROR when other player presses spawn button(not when self):

    RPC call failed because the function "Spawn" does not exist in any script attached to "Chat"

    PS. Can the RPC call send many values or do I have to do it a other way?
     
    Last edited: Mar 24, 2013
  10. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    I got that fixed, but there is a new problem. When the button is pressed it creates both players new instances.
    Example: Player creates box. He sends RPC call to create box, but it creates a box to every player location.
    RPC calling is the same.


    Code (csharp):
    1. [RPC]
    2.     private void Spawn(string values)
    3.     {
    4.  
    5. Network.Instantiate(object1,Vector3.zero, Quaternion.Euler(Vector3.zero), 0);
    6. }
    7.  
    A photo of the bug:
    $bug.jpg
     
  11. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    I don't think you get the idea of what networking is.. RPC's are Remote Procedure Calls.. this means they are called on each system.

    When you are create something in the RPC, it will be created in each instance.. as this is what it is supposed to do.

    My suggestion to you at this point is to read as many tutorials as you can, and wrap your head around what networking is about, and why things work the way they do. Once you understand the theory, what you are trying to do might make more sense.

    Maybe it might be better for you to explain exactly what it is you are trying to do?
     
    Last edited: Apr 1, 2013
  12. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    I want them to be called on each system. So that every player sees the created box. Problem is that it creates boxes for every player. So when there is 1 player it creates 1, but when there is 2 creates 2 boxes when it should make only 1. (This was before these problems). There is always only 1 object that haves this code. This object haves networkview component.


    EDIT:
    If I turn off the networkview component it makes errors becouse it doesn't exist, but it creates the objects the way I want. Any ideas? (Object won't get any sent values)
     
    Last edited: Apr 1, 2013
  13. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    network instantiate instantiates against all clients.. you call the RPC in a buffered state..

    player 1 pushes button, RPC is called to instantiate network object (creates buffered on all systems)
    player 2 gets the RPC call and instantiates network object (that also creates an object on each system)
    etc..

    The problem is this.. you are using an RPC call that does another network call.. try just calling the network instantiate from the button press.. BAM, problem solved.

    Take the time to sit down and understand what is going on here, like I suggested above. Don't just jump to the forums when you are having the slightest problem.

    Also as a note.. instead of Quaternion.Euler(Vector3.zero), do Quanternion.Identity
     
  14. Fegloy

    Fegloy

    Joined:
    Mar 20, 2013
    Posts:
    6
    Yeah I figured it out too. I have just started using RPC calls, but now I have one problem. I need to set some values to the created object.
    Code (csharp):
    1.  
    2. GameObject Box = Network.Instantiate(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<ConnectionScript>().Box,
    3. Vector3.zero,Quaternion.identity, 0) as GameObject;
    4. Box.GetComponentInChildren<Controller>().value1=value2;
    5.  
    How can I turn this into RPC or something like that so that other players get the values too?
     
    Last edited: Apr 2, 2013
  15. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    Send the values in the rpc?

    lol
     
  16. kurtdesi

    kurtdesi

    Joined:
    Dec 10, 2013
    Posts:
    7
    i am having a similar issue that i cant quite figure out ... what i did is iv put a script on the player prefab that says i.. if collision.gameObject.name == "server player " .. debug.log(ismine) , else if collision.gameObject.name == "client player " .. debug.log(ishis) ...... This is working out when the player collides with the clients player ... but is not working out vice versa .. its like no collision is being detected.. PLEASE HELP iv been stuck on this for a week ! I am ready to pay for some help.
     
  17. Bob-The-Zealot

    Bob-The-Zealot

    Joined:
    Jan 18, 2015
    Posts:
    1
    Do you still need help?