PhotonView.instantiationData is null, when it shouldn't be

Ok, PhotonView.instantiationData always returns null, and I have no idea why.

In my character class I call this when the character dies. the variable "loot" is an int.

[code2=csharp]if (PhotonNetwork.isMasterClient && loot > 0)
{
//drop loot pickup
object[] data = new object[1] { loot };
PhotonNetwork.InstantiateSceneObject("PlayerLootPickup", BodyPosition, Quaternion.identity, 0, data);
}[/code2]

Then I have a PlayerLootPickup object (which I just instantiated above). In the Awake method of the PlayerLootPickup script, I do this:
[code2=csharp]_photonView = gameObject.GetComponent<PhotonView>();
object[] data = _photonView.instantiationData;
if (data == null)
{
FoFDebug.LogWarning("warning - data null");
lootAmount = 0;
}
else
lootAmount = (int)data[0];[/code2]

The problem is, data is always null! I have verified that the data object I am passing into InstantiateSceneObject is not null, but when I try to get it back through PhotonView.instantiationData - it's always null!

I have no idea what is going on - can anyone help? Anyone know what might cause this?

Comments

  • Ok, I think I've fixed it!

    I put the code to retrieve the data in Start() instead of Awake(), and it seems to work.

    Now so as not to be completely embarrasing, I must explain that the reason I didn't think that was the problem initially is because before this, I was doing something very similar - retrieving the data in the Awake() method - and it *did* work in that case! I can only assume that putting it in Awake() is dodgy and sometimes works and sometimes doesn't, because of the order at which things get initialised maybe? Whereas putting in Start() is guaranteed to work...or something?
  • In 1.18 I tried to do my best to initialize everything for a PV before it's Awake method gets called. It's a bit tricky, cause once we call GameObject.Instantiate, we can't control the order in which scripts get awakened.
    Start is a good workaround, cause it's always called after our scripts did their work.

    Are you using PUN 1.18 or an "older" version?
  • An older version I think. Good to know the workaround is easy and reliable though, it suits me fine to just keep it in Start().
Sign In or Register to comment.