Grab an object

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

Tobias
2022-02-24 13:40:08

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.

mesmes
2022-02-27 08:12:49

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?

Tobias
2022-02-28 10:58:28

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.

mesmes
2022-02-28 12:17:01

Thank you !

Back to top