Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Sab44 · Aug 03, 2017 at 10:58 PM · networkingphotondynamicowner

Photon Networking: how to take over ownership?

Hi, I'm using Photon to instantiate 2 world objects. Since I don't want duplicates, I made sure that only the first client to join the room will trigger the spawn by:

  if(PhotonNetwork.isMasterClient)
  {
  GameObject cad = PhotonNetwork.Instantiate("CAD_Photon", Vector3.zero, Quaternion.identity, 0);
  GameObject cad2 = PhotonNetwork.Instantiate("CAD_Photon2", Vector3.zero, Quaternion.identity, 0);
  }

So that works fine. I used the "isMasterClient" condition and not "InstantiateSceneObject" directly, since I understand that this makes the MasterClient the permanent owner of that object.

Now I can manipulate the object on the host's side and these manipulations will be synced to the client. On the client side, I can also manipulate the objects, but these changes are not synced to the host.

From reading and researching I figured out, I need to be able to switch ownership to the client so his changes will be synced to the host. But I just couldn't find any proper instructions on how to actually do it in a dynamic way. The "Owner" setting of the "PhotonView" components are set to "Takeover", but I guess I will have to use some kind of dynamic method on my object grabbing script that automatically changes ownership to the one who is grabbing the object.

Here is my script for simple object manipulation (grabbing it for reposition and rotation):

 public class ObjectController : MonoBehaviour
 {
     private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
 
     private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
     private SteamVR_TrackedObject trackedObj;
 
     private GameObject pickup;
 
     void Start()
     {
         trackedObj = GetComponent<SteamVR_TrackedObject>();
     }
 
     void Update()
     {
         if (controller == null)
         {
             Debug.Log("Controller not initialized");
             return;
         }
         
         if (controller.GetPressDown(triggerButton) && pickup != null)
         {
             pickup.transform.parent = this.transform;
         }
 
         if (controller.GetPressUp(triggerButton) && pickup != null)
         {
             pickup.transform.parent = null;
         }
     }
     
     private void OnTriggerEnter(Collider collider)
     {
         pickup = collider.gameObject;
     }
 
     private void OnTriggerExit(Collider collider)
     {
         pickup = null;
     }
 }

So how do I actually implement a change in ownership? I guess it's not that hard and I am just missing a simple function, but I can't get it to work.

Thank you very much for every help or advice! I really appreciate it!

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

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

Answer by Sab44 · Aug 04, 2017 at 02:52 PM

I managed to fix it. The solution is to check if you're the owner, and if you aren't, to transfer ownership to yourself.

 if (controller.GetPressDown(triggerButton) && pickup != null)
         {
             if (pickup.GetComponent<PhotonView>().ownerId == PhotonNetwork.player.ID)
             {
                 grabObject();
             }
             else
             {
                 pickup.GetComponent<PhotonView>().TransferOwnership(PhotonNetwork.player.ID);
                 grabObject();
             }
         }

Hope this helps someone who had the same struggle as me.

Comment
Add comment · Show 6 · 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 dNazarik · Nov 21, 2017 at 01:44 PM 0
Share

Did you try to set "Takeover" option to the object? I tried but it didn't work.

avatar image jacobvrodgers · Jul 27, 2021 at 10:38 PM 0
Share

Thanks for the answer, here's updated version for anyone else. alt text

help2.png (45.4 kB)
avatar image afakul jacobvrodgers · Jul 28, 2021 at 07:59 PM 0
Share

just to make sure ,you place this inside ontriggerenter right ?

avatar image afakul jacobvrodgers · Jul 28, 2021 at 08:00 PM 0
Share

can you explain the seconds " if stantement " is for what ?

avatar image afakul jacobvrodgers · Jul 28, 2021 at 08:03 PM 0
Share

hitobject.GetComponent().Owner.ActorNumber == PhotonNetwork.LocalPlayer.ActorNumber

this is for what

avatar image macattackbok afakul · Jul 29, 2021 at 10:20 PM 0
Share
  1. This is placed inside ontriggerenter

  2. There first if statement is to check if you have an object, if it's on the right layer, the second if statement is to check ownership, if player owns it grabobject(), else make player own it then grabobject()

  3. To see if the owners number is = to the current players number. Hence, ownership.

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

105 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

Related Questions

Only do something if it has the same tag as the player 2 Answers

[Photon]Player vs. Player Collision 0 Answers

Correct way to design turn based multiplayer using Photon Unity Networking. 0 Answers

how do i apply damage to objects other that the player 1 Answer

Photon - character not moving after next Scene Load 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