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 /
avatar image
0
Question by HarD-izzeR · Jul 21, 2019 at 04:19 AM · networkinginstantiatetransformphoton

PUN2 Chess game instantiation problem

Hi, I made a chess game, it works perfectly in single player and wanted to add a multiplayer mode, so I found PUN2. Originally all chess pieces are instantiated on start, When I tried not to change it, so I just added a photon view and photon transform view classic components and built the game, when I move a piece it shows on one side only. So I tried PhotonNetwork.Instantiate and it worked on both sides well, but it instantiated every piece twice, so there are two white teams and two black teams.. Then I tried PhotonNetwork.InstantiateSceneObject and it didn't instantiate every team twice, and it transmitted the movement on both sides, but I can move the pieces on only one side, on the other client it just doesn't work. Also when using InstantiateSceneObject all pieces have "Controlled Locally" turned off in the photon view component.. while using PhotonNetwork.Instantiate all pieces have it turned on and on the doubled pieces it is turned off. Problem: How can I use PhotonNetowrk.Instantiate without doubling teams. or how can I use PhotonNetwork.InstantiateSceneObject but control the ownership of teams, so that one client owns white team and other owns black team, or even both I think I can work around it if both can control both teams.. Thanks :D.

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 Captain_Pineapple · Jul 21, 2019 at 08:47 AM 0
Share

Can you perhaps share some code snippets of your instantiation? Where and how do you call it?

2 Replies

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

Answer by Captain_Pineapple · Jul 21, 2019 at 06:18 PM

Hey,

please read the documentation on PhotonNetwork.Instantiate carefully...

 GameObject goM = PhotonNetwork.Instantiate(chessmanPrefabs[index].name, GetTileCenter(x, y), Quaternion.identity) as GameObject;

when you call your instantiation you apparently do this for every player for every chesspiece. When you call PhotonNetwork.Instantiate("Rock") at player A, it will create a chesspiece of type "Rock" for player A, giving him ownership, but also instantiate the same object for ALL other players in the room or joining later. So a solution might be that the masterclient always is white and only spawns the white chesspieces while the "non master client" spawns the black ones...

Comment
Add comment · Show 15 · 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 HarD-izzeR · Jul 21, 2019 at 07:42 PM 0
Share

Thanks for replying, I changed the start function to be like this:

 private void Start() {
         Instance = this;
         pv = GetComponent<PhotonView>();
         if (PhotonNetwork.Is$$anonymous$$asterClient)
             SpawnWhiteChessmans();
 
         pv.RPC("SpawnBlackChessmans", RpcTarget.Others);
     }

And now the white $$anonymous$$m is spawned and only master has its ownership. now how do I make the other client spawn the black $$anonymous$$m ? i tried RPC and it didn't work.. Am I missing something ?

avatar image Captain_Pineapple HarD-izzeR · Jul 21, 2019 at 08:04 PM 0
Share

why not:

 if (PhotonNetwork.Is$$anonymous$$asterClient)
         SpawnWhiteChessmans();
 else
         SpawnBlackChessmans();

This assumes though that there will never be more than 2 people in one room!

avatar image HarD-izzeR Captain_Pineapple · Jul 21, 2019 at 08:43 PM 0
Share

Yeah I tried it before, and somehow only the black king is spawned and the other client cant control it and neither does the master.. White $$anonymous$$m is working perfectly tho.. only master can control it and the client cant..

Show more comments
avatar image
0

Answer by HarD-izzeR · Jul 21, 2019 at 02:41 PM

Any ideas ??

Comment
Add comment · Show 2 · 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 Captain_Pineapple · Jul 21, 2019 at 03:29 PM 0
Share

As i wrote in my comment above... please share some code snippets. Where do you call the instantiation? did you make sure it really is only called once? Does everyone only instantiate his figures or all of them? please provide some more information on what you do in your code.

avatar image HarD-izzeR · Jul 21, 2019 at 03:39 PM 0
Share

Sure here is the code: https://pastebin.com/Anp2jtD8 As mentioned above.. the instantiation is called in start. (SpawnAllChessmans(); at line 28) And originally it is instantiated only once so I'am sure the whole chess code is working perfectly. its just the multiplayer part.

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

199 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 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

Networking already instantiated assets 1 Answer

Photon Network Instantiate Objects over Network 1 Answer

Photon Networking: LocalScale transform doesn't work 1 Answer

[Photon] Looking for example code for late joining clients syncing instantiated game objects that don't exist in the base scene 0 Answers

Using RPC to Instantiate 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