RPC Function is not being recognized

I have been getting the following errors when trying to compile an RPC Function to Unity. I'm new to RPCs, but I have been looking at other threads and I can't seem to find one with this error.

My code is shown below, that calls the RPC Function.

It seems to have a problem with RPC in general, as the line it is getting an error on is 113, where it says [RunRPC].

Here are some import statements I make at the top, incase I am missing one.

Any help would be greatly appreciated! (:

Best Answer

  • tleylan
    tleylan ✭✭
    Answer ✓

    Well perhaps you've discovered it by now but you named the Attribute RunRPC not PunRPC.

    I'll suggest you follow the C# naming conventions (for the most part) as well. So class playerMovement should be PlayerMovement.

    Your respawn method should be Respawn and (as a rule) consider adding the optional "private" to the signature so: private void Respawn()

Answers

  • Also, If I comment out line 113, (which doesn't seem reasonable, but why not try it) the code actually compiles, but I get this error message when it tries to call the (Non-existent)rpc function


    I should note that I am also not entirely sure if I should be using an RPC function in this scenario. There may be some other way of doing this, but here is what I am actually trying to do: I have a top down game and I have finished making the players be able to damage each other with two different weapons. What I want to do now is when their health falls below zero, they should respawn in a new randomized position on the map. I have gotten the function that finds a new position to work properly, and I think almost all of the concept I am trying to do works, except when I set the Player's new position, it seems to flash at that position, and then immediately glitch back to it's current position.

    The following function gets called when a player's health falls below zero. I think the issue is in the line with the red arrow.

    This script does not give any console errors, but it does not do what it should. The respawning player is supposed to move to the new position, and it appears to for a split second, but it instantly goes back to/stays where it is instead. Maybe I need a master client to move the respawning players? Maybe what's happening is the player tries to move to the new position, but then the Photon Transform View Classic teleports it back because it's trying to sync it's position?

  • tleylan
    tleylan ✭✭
    Answer ✓

    Well perhaps you've discovered it by now but you named the Attribute RunRPC not PunRPC.

    I'll suggest you follow the C# naming conventions (for the most part) as well. So class playerMovement should be PlayerMovement.

    Your respawn method should be Respawn and (as a rule) consider adding the optional "private" to the signature so: private void Respawn()

  • Thanks! It compiles now. I can't believe I missed that. I must have read it wrong this whole time. 🤦🏻‍♂️