Reporting Bug With PunUtility

GreedyVox

Active member
Hi Justin,
Reporting a Bug I found in the PunUtility.cs with the funcion RetrieveGameObject, return null GameObject when the variable itemSlotID == -1

ObjectIdentifier objectIdentifier = null;
if (!idObjectIDMap.TryGetValue(id, out objectIdentifier)) {
// The ID doesn't exist in the cache. Try to find the object.
var hitPhotonView = PhotonNetwork.GetPhotonView((int)id);
if (hitPhotonView != null) {
gameObject = hitPhotonView.gameObject;
} else {
// The object isn't a PhotonView. It could be an ObjectIdentifier.
var objectIdentifiers = parent == null ? GameObject.FindObjectsOfType<ObjectIdentifier>() : parent.GetComponentsInChildren<ObjectIdentifier>();
if (objectIdentifiers != null) {
for (int i = 0; i < objectIdentifiers.Length; ++i) {
if (objectIdentifiers.ID == id) {
objectIdentifier = objectIdentifiers;
break;
}
}
}
idObjectIDMap.Add(id, objectIdentifier);
if (objectIdentifier != null) {
gameObject = objectIdentifier.gameObject;
}
}
}


I fixed this for myself and sharing

ObjectIdentifier objectIdentifier = null;
if (!idObjectIDMap.TryGetValue (id, out objectIdentifier)) {
// The ID doesn't exist in the cache. Try to find the object.
SpawnManager.SpawnedObjects.TryGetValue (id, out var hitPhotonView);
if (hitPhotonView != null) {
gameObject = hitPhotonView.gameObject;
} else {
// The object isn't a PhotonView. It could be an ObjectIdentifier.
var objectIdentifiers = parent == null ? GameObject.FindObjectsOfType<ObjectIdentifier> () :
parent.GetComponentsInChildren<ObjectIdentifier> ();
if (objectIdentifiers != null) {
for (int i = 0; i < objectIdentifiers.Length; ++i) {
if (objectIdentifiers.ID == id) {
objectIdentifier = objectIdentifiers;
break;
}
}
}
idObjectIDMap.Add (id, objectIdentifier);
}
}
if (objectIdentifier != null) { gameObject = objectIdentifier.gameObject; }

 
Last edited:
Thanks for posting your fix. What was the issue so I can understand? If itemSlotID is -1 then it will search for the ObjectIdentifier within the scene or by a PhotonView. It looks like you are getting the PhotonView from the SpawnManager but not all PhotonViews will be registered with the SpawnManager.
 
Hey mate,
To be honest, not using photon at all, implemented MLAPI for networking, I noticed after the latest update of the multiplayer addon in the PunUtility.cs, everything working fine adding to the cache and return a GameObject but there wasn't any retrieving of the cache and returning a GameObject.

if (objectIdentifier != null) { gameObject = objectIdentifier.gameObject; }

So I moved the line out outside of the TryGetValue, just like the previous version.
 
Top