SetCustomProperties Problems cause of Coroutine ??

Hey,

I spend a lot of time on this problem and without success.
I juste try to set a property to a PhotonPlayer when he initialized the Game.

I use something like this on my mainCode :

CommonData.networkManager.playerInitializedGame = true;

In my NetworkManager, i have this property :
public bool playerInitializedGame
{
	get { return PhotonNetwork.player.GetGameInitialized();}
	set { PhotonNetwork.player.SetGameInitialized(value); }
}
And In my PhotonPlayerExtension (static Class) :
public static void SetGameInitialized(this PhotonPlayer player, bool isInitialized)
{
	if (player == null || player.CustomProperties == null)
	{
		return;
	}

	Hashtable playerProp = new Hashtable();
	playerProp[GameInitializedPropKey] = isInitialized;

	player.SetCustomProperties(playerProp);
}
So far it works ! My property change. BUT i don't know why the trigger "OnPhotonPlayerPropertiesChanged" didnt trigger.
// Some Code in OnPhotonPlayerPropertiesChanged function ... 
else if (props.ContainsKey("GInit"))
 {
Debug.Log("OnPhotonPlayerPropertiesChanged Game Initialized");
}
After many tests, i find that in my code if i comment a line code when i use a Coroutine to display several object on screen with delays that is before i changed the player property. It works perfectly... I can't explain why :S

Sorry for the long post, hope i'm understandable

Pizzi

Comments

  • Hi @Pizzi,

    BUT i don't know why the trigger "OnPhotonPlayerPropertiesChanged" didnt trigger.


    Please make sure that you are using the correct callback including the correct parameters. It is void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps). Please let me know, if you are already using the correct one and it doesn't get called on Player Custom Properties update.

    After many tests, i find that in my code if i comment a line code when i use a Coroutine to display several object on screen with delays that is before i changed the player property.


    Please let me know if I get this correctly: it is only working properly if the Coroutine or a certain line of code inside this Coroutine is not used / commented? Can you tell me, what exactly you are doing in this Coroutine and maybe paste a code snippet from that function?
  • Thanks Christian_Simon for your answer, and yes it's exactly that.
    I'll show you my full test and with the Debug.Log.

    Here i change my player property (as I said in first message) :
    Debug.Log("A");
    CommonData.networkManager.playerInitializedGame = true;
    Debug.Log("B");
    My PhotonPlayerExtension Class :
    public static void SetGameInitialized(this PhotonPlayer player, bool isInitialized)
    {
    	// Some Codes
            Debug.Log("SetGameInitialized " + isInitialized);
    }
    And I add a Debug.Log in my trigger :
    public override void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
    {
    	Hashtable props = playerAndUpdatedProps[1] as Hashtable;
            if (props.ContainsKey(PhotonPlayerExtensions.GameInitializedPropKey))
    	{
    		Debug.Log("OnPhotonPlayerPropertiesChanged GameInitialized");
    	}
    }
    And my famous Coroutine :
    public IEnumerator DisplayBattlefields()
    {
    	foreach (GameData.Battlefield item in CommonData.GameLogic.grid.battlefields)
    	{
    		item.gameObject.SetActive(true);
    		yield return new WaitForSeconds(0.2f);
    	}
    
    	manager.HandleGameEvent(GameEvents.OnBattlefieldsDisplayed, null);
    	yield return null;
    }
    When I test :

    A
    SetGameInitialized True
    B

    And if I comment this specific line :

    // yield return new WaitForSeconds(0.2f);

    I retest :

    A
    OnPhotonPlayerPropertiesChanged GameInitialized
    SetGameInitialized True
    B

    Hope it helps, sorry for long post :)
  • I'm missing the connection between setting the Player Properties and running the Coroutine. Can you please give me a quick explanation about it?

    Besides that I currently don't know, what the problem might be.
  • Ok. Basically, I've several States Class in a Stack, here GamePlay and GameInitialization States.
    When I begin my game, I start with GamePlay in the Stack who add directly GameInitialization class.
    In this class, I make some initializations and make my Coroutine.
    When this Coroutine is finished, it triggers an event that drop my GameInitialization Class from my Stack and return to GamePlay. When I return in GamePlay Class, i have function and if i'm from the GameInitialization Class, i set my PhotonPlayer Property.

    CommonData.networkManager.playerInitializedGame = true;

    That's It.
    Without doubt, i make something wrong or my project is maybe unstable...
    I find another way to do what i want with a raiseEvent in "my SetGameInitialized" function (and it works).
    But i'm interesting to know why when i changed my PhotonPlayer property, it doesn't trigger "OnPhotonPlayerPropertiesChanged" function...
  • Glad to hear, that you have found another solution to the problem at least.

    But i'm interesting to know why when i changed my PhotonPlayer property, it doesn't trigger "OnPhotonPlayerPropertiesChanged" function...


    I sadly can't tell you. The only thing you can do is to debug the code, starting with the SetCustomProperties call and check if this one actually gets processed. You can then follow the processed steps and see, if OpSetPropertiesOfActor gets called as well. Inside this function you can check if the Operation gets send (OpCustom call). Back to the SetCustomProperties function, you can also check, if NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, customProps); gets called and inside that function, which objects are inside the objectsToCall Hashset. Here you can check, if the Hashset actually contains the object with the OnPhotonPlayerPropertiesChanged callback.
  • OK ! I'll try this asap.
    I will keep you informed if i find something ;)
    Thanks a lot