Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 NWegener · Jun 28, 2012 at 08:26 PM · networkrpc

RPC-Function not Called, but no Error

I have a Problem with an RPC-Call, where an Enemy should be called on the Server-Side. Here is the Code:

  function Awake() {
      wallWalker = Resources.Load("WallWalker") as GameObject;
      spawnWallWalker();
      }
      function resetOther() {
      if (spawn) {
          GameObject.Destroy(spawn);
      }
      spawnWallWalker();
      }
      function spawnWallWalker() {
      if (Network.peerType != NetworkPeerType.Disconnected) {    
          //Only Spawn Wallwalker on Server
          networkView.RPC("spawnWallWalkerRPC", RPCMode.Server);
      } else {
          spawnWallWalkerRPC();
      }
      }
      @RPC
      function spawnWallWalkerRPC() {
      if (Network.peerType != NetworkPeerType.Disconnected) {
          spawn = Network.Instantiate(wallWalker, transform.position, Quaternion.identity, 0);`
      } else {
          spawn = GameObject.Instantiate(wallWalker, transform.position, Quaternion.identity);
      }
      spawn.GetComponent(WallWalker).spawn(transform.position, horizontalMax, verticalMax);
      }



Everything works fine, except after networkView.RPC("spawnWallWalkerRPC", RPCMode.Server); the Function spawnWallWalkerRPC is not called, and Unity does not display an Error.

I really have no Idea where the problem lies, maybe I'm missing something obvious. Help is very much appreciated.

Comment
Add comment · Show 4
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 whydoidoit · Jun 28, 2012 at 08:26 PM 2
Share

Are you calling this code on the server? RPC$$anonymous$$ode.Server doesn't work on the server

avatar image asafsitner · Jun 28, 2012 at 09:20 PM 2
Share

As whydoitdoit said RPC$$anonymous$$ode.Server doesn't work if the player sending the message is the server. You need to add a check for Network.isServer and if so, just invoke the function, not as RPC.

avatar image NWegener · Jun 28, 2012 at 09:33 PM 0
Share

Thanks whydoidoit and asafsitner, that was the solution. Thanks again.

avatar image whydoidoit · Jun 28, 2012 at 09:33 PM 0
Share

I'll post it as answer for future generations :)

1 Reply

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

Answer by whydoidoit · Jun 28, 2012 at 09:34 PM

You cannot RPC a function on the server using RPCMode.Server from the Server itself. You need to directly call the server function when Network.isServer returns true.

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

6 People are following this question.

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

Related Questions

Send GameObject active in network to all clients 2 Answers

Disconnect a player from a network 1 Answer

Network.Destroy(), Couldn't perform remo 0 Answers

RPC call not sending correct data 0 Answers

Empty RPC functions. 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