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 Borzi · Dec 13, 2013 at 04:24 PM · networkinginstantiatemultiplayerrpc

PhotonView over GameObject

Hey guys, I am trying to get a peace of code to work. The problem with converting from Unity Network to Photon is that for some reason I get an error when trying to call the photonView from the last player variable because its a GameObject (which works over networkView, the normal unity networking). I'll list both scripts, one from the Photon and one from the Unity MasterServer, because I think that might help. Any help is appreciated, thank you in advance!

Unity MasterServer (works):

 [RPC]
     public void Client_PlayerJoined(string Username, NetworkPlayer id)
     {
         Player temp = new Player();
         temp.PlayerName = Username;
         temp.OnlinePlayer = id;
         PlayerList.Add(temp);
         if(Network.player == id)
             {
                 MyPlayer = temp;
                 GameObject LastPlayer = Network.Instantiate(SpawnPlayer, Vector3.zero, Quaternion.identity, 0) as GameObject;
                 LastPlayer.networkView.RPC("RequestPlayer", RPCMode.AllBuffered, Username);
                 temp.Manager = LastPlayer.GetComponent<UserPlayer>();
                 Debug.Log("Spawned Player");
             }
     }

PhotonCloud Version (Error: Type UnityEngine.GameObject' does not contain a definition for photonView' and no extension method photonView' of type UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?))

 [RPC]
     public void Client_PlayerJoined(string Username, PhotonPlayer id)
     {
         Player temp = new Player();
         temp.PlayerName = Username;
         temp.OnlinePlayer = id;
         PlayerList.Add(temp);
         if(PhotonNetwork.player == id)
             {
                 MyPlayer = temp;
                 GameObject LastPlayer = PhotonNetwork.Instantiate("RigidBodyPlayer", Vector3.zero, Quaternion.identity, 0) as GameObject;
                 LastPlayer.photonView.RPC("RequestPlayer", PhotonTargets.AllBuffered, Username);
                 temp.Manager = LastPlayer.GetComponent<UserPlayer>();
                 MyPlayer.PlayerName.photonView.RPC("RequestPlayer", PhotonTargets.AllBuffered, Username);
                 Debug.Log("Spawned Player");
             }
     }
Comment
Add comment · Show 1
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 Borzi · Dec 14, 2013 at 10:15 PM 0
Share

No ideas at all?

2 Replies

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

Answer by OP_toss · Dec 15, 2013 at 08:15 PM

The error seems to tell you exactly what's wrong. There is no definition for "photonView" on a GameObject. So instead, get the photon view component using gameObject.GetComponent(), assuming that's the correct type name. Then call your RPC on that.

Also I assume you know that the prefab "RigidBodyPlayer" needs to have a PhotonView attached for you to be able to Network.Instantiate it.

Hope this helps!

Comment
Add comment · Show 3 · 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
avatar image Borzi · Dec 15, 2013 at 08:55 PM 0
Share

Thanks for your reply! That solves half of the question because it worked :) The second is how to get the networkView via string ($$anonymous$$yPlayer.PlayerName). Do you have any idea of how to do that?

avatar image OP_toss · Dec 15, 2013 at 09:20 PM 0
Share

I'm not sure you need to, but assu$$anonymous$$g you do, use GameObject.Find( "GameObjectName" ).GetComponent().

I don't suggest using GameObject.Find. I can almost gaurantee with a little rework, you can avoid it entirely. You can send networkViewIDs via RPCs in uLink. Don't know about Photon. You can keep a dictionary of players, then lookup the player gameobject by name. etc. etc.

Also please mark correct if this solved your problem. Thanks!

avatar image Borzi · Dec 16, 2013 at 04:00 PM 0
Share

Yeah it works thanks, I recon there is an error with my code but thanks anyway! What I ended up doing was making a transform part of "$$anonymous$$yPlayer" and using that to photonView.GetComponent().

avatar image
1

Answer by Meatgrind · Sep 29, 2014 at 08:15 AM

Photon Unity Networking (PUN) expects you to inherit your classes from their extended Photon.MonoBehaviour like this:

public class MyClass : Photon.MonoBehaviour //...

Their MonoBehaviour is extended to cache this.photonView so you don't need to do the GetComponent setup for every script that uses PhotonView. Of course, as previous answer mentioned, the PhotonView component has to be attached to the prefab you are trying to PhotonNetwork.Instantiate.

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

19 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

Related Questions

Unity networking tutorial? 6 Answers

Photon Networking Instantiating Problem 0 Answers

Objects instantiated by player owned object aren't owned by the player? 2 Answers

Using .SetActive() over Unity Network for multiplayer. (Enable weapons on clients) 1 Answer

Proper way to instantiate projectile in PUN 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