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 /
This question was closed Apr 25, 2019 at 04:02 AM by $$anonymous$$.
avatar image
0
Question by $$anonymous$$ · Apr 24, 2019 at 04:54 AM · instantiatephotonrpc

Photon RPC methodcall

So I have code for instantiating an object with an RPC call with Photon but it doesn't work. I get the debugger message of "RPCs can only be sent in rooms. Call of "Fire" gets executed locally only, if at all." The code is:

 button.onClick.AddListener(Task);

 [PunRPC]

 void Task()
 {
     PhotonNetwork.CreateRoom("Room1");
     PhotonNetwork.JoinRoom("Room1");
     PhotonNetwork.LoadLevel("Map1");
     PhotonNetwork.AutomaticallySyncScene = true;

     if (PhotonNetwork.JoinRoom("Room1") == true)
     { 
         PhotonView photonview = GameObject.Find("FPSController").GetComponent<PhotonView>();
         photonview.RPC("Fire", RpcTarget.AllBuffered);
     }
 }

 void Fire()
 {
     PhotonNetwork.Instantiate("FPSController", new Vector3(316, 0, 124.4414f), transform.rotation);
 }

Any help would be fine

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

1 Reply

  • Sort: 
avatar image
0

Answer by Captain_Pineapple · Apr 24, 2019 at 09:14 AM

Hey there,

there are multiple thing that i'd suggest to change in your code. The most crutial part here is that when you create a room and join a room, you should ALWAYS wait until the action was actually completed by photon. Use the Callbacks offered by Photon for this. The error you get indicates that you try to call Fire when you have not yet joined a room. You can only join rooms if the Callback OnJoinedRoom was triggered. So whenever you try to call upon an RPC there should always be a check on PhotonNetwork.InRoom (might not be exactly the right syntax, depending if you use photon 1 or 2) before it's call. Only if this is true you can call rpcs.

Also about your fire function: Simply don't do this. PhotonNetwork.Instantiate will work on your instance the same as the usual normal Instantiate(...) but it will also automatically create the same object at the same position at all other players that are currently in the room or join later on. So remove the Fire rpc completly and only instatiate the player object at your local game istance when you receive the OnJoinedRoom Callback.

Check out this list HERE for all available callbacks that photon offers. If something was not clear or you have further questions feel free to ask.

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

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

differentiate cloning objects with different tag names on PUNRPC 0 Answers

Photon Network Instantiate Objects over Network 1 Answer

Proper way to instantiate projectile in PUN 1 Answer

Destroying the bullet over a photon network 4 Answers

Photon synchronization on different devices failes 0 Answers


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