Grab an object
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Grab an object
mesmes
2022-02-24 07:30:02
Hi !
I have object "X" in my scene. He has the following properties:
PhotonView
Photon Rigidbody View
XR Grab Network Interactable (I override the class by adding the following):
protected override void OnSelectEntered(XRBaseInteractor interactor)
{
photonView.RequestOwnership();
base.OnSelectEntered(interactor);
}
So all works good but, When I want to duplicate (i mean-Instantiate) "X" and assign him to different object I have the following errors:
1.) PhotonView ID duplicate found: 1. New: View 1 on X(Clone) (scene) old: View 1 on X(scene). Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.
2.) InvalidOperationException: Duplicate key 1
ExitGames.Client.Photon.NonAllocDictionary`2[K,V].Add (K key, V val) (at <4c05f01c27d1415bafcda4c1ab7160e0>:0)
Comments
Use PhotonNetwork.Instantiate() on a prefab, to get unique networked objects.
The duplicate key happens because you duplicate a networked object and thus assign the viewID. It can't be stored under the same ID twice, however.
Thank you for your answer.
My problem is that I need object "X" will be a network object for others to see it or use it before/after me.
When I am using it I want to duplicate it.
If I cant do it, How can I have a reference/name of the object I just grab?
If I can get the network object name for example I can instantiate it directly from resources/online source without the error. (and not instantiate the original network object)
Am I right?
The PhotonView.viewID is the reference. With it, you can find the related object. If it stores the name of it's prefab somewhere, you can instantiate that.
Thank you !
Back to top