Queue, Users, & Syncing

Options
I had a few questions about some issues I've failed to find help for! Hopefully I can get help on one or more of these, since you guys are so awesome at helping out!

Problem #1- Queue Incoming Crashes
First off, I've been getting a lot of Queueincomingunreliable warnings that eventually crash the entire server due to my CustomProperties.

Previously, I called SetCustomProperties, added values to the hashtable, and set each player to receive them all (via Photonview.player.customproperties) in the Update function. This worked just as I wanted it to, but the Queue warnings crashed everything, including de-syncing the transforms across all clients and even disconnecting from the Chat.

But when I create my hashtable, add the values after they've been given values, and call SetCustomProperties a few seconds after the character connects to our lobby with Start() and a coroutine that waits 10 seconds,, and then only call to receive and use the values in Update(), I don't get the effect I was looking for (in fact I get no effect whatsoever, as though all the values are null), and since the values don't send, I get no Incoming warnings and transform sync again accurately.

Problem #2 - # Users Online
Wanted to verify that there is still no way to use PHP or any other way to get your # of Users from Photon Cloud to put on your website. I know having an updating count of how many users are connected would really make people want to play more! Going off of the information from this, but it's from 2013 ---> forum.unity3d.com/threads/photon-players-online-for-website.195797/

Figured out a different way to do this!

Problem #3 - NPC's Position/Transforms Failing to Show or Sync
Probably a simple fix, but I've tried multiple different kinds of Photon Views to solve this to no avail.
Say I added a knight who just walks around/wanders aimlessly after being instantiated from Photon.Instantiate. If only one person is online, (no data being sent around) the knight will move just a little bit, and then stop moving and rotate in place, and send the Debug log loads and loads of errors. As soon as a second player comes in, the knight disappears. If the knight was instantiated while two people are connected, the knight will appear for a moment and then disappear completely. If the answer is fairly simple and you'd rather just nudge me in the right direction, I guess what I'm asking is Are there any Photon Demos I should look at for a good example of how to handle this?

Comments

  • nzbrockstar
    Options
    Hello Kitty,
    I have solution for your NPC movement problem, I've attached a screenshot on how I've used the photon components. You can have a look at MarcoPolo sample project provided with Photon Projects in Assets store for free !

    Use the movement script from marcopolo example. And make the arrangement of the components in the same way as shown in screenshot. i57.tinypic.com/1qiask.png and i58.tinypic.com/2ey8jti.png


    Please help me on How to use custom properties. As I've to save lot of settings of my heros hp, damage , etc and sync these values over all the clients. I'm changing these values on runtime on each client when they are in lobby. Can I use custom properties for it ? I don't know what are custom properties and how can I use them.
  • kittyLLLL
    Options
    Thanks, nzbrockstar! I'll try those out later.

    Custom properties were difficult to figure out, but basically what they are is a group of values that you want read by every player in the room. I'll give you an example and I'll explain the most important parts for you.

    Here is an example of my nametag script! It uses custom properties to send both the Photon player's name, and a custom secondary name for each character.

    using UnityEngine; using System.Collections; public class nametag : MonoBehaviour { private ChatGui chat; public GUIStyle namePlatestyle; private Vector3 namePlatePos; public Vector3 offset; public string username; public string charname; public bool showNametag = true; void Update() { GameObject gameMan = GameObject.Find ("GameManager"); charname = gameMan.GetComponent<MyInfo>().characterName; ExitGames.Client.Photon.Hashtable nameTag = new ExitGames.Client.Photon.Hashtable(); nameTag.Add ("charName", charname); PhotonNetwork.SetPlayerCustomProperties(nameTag); if (this.gameObject.GetComponent<Renderer>().isVisible == false) { if(GetComponentInParent<PhotonView>().isMine) showNametag = false; } else showNametag = true; } void OnGUI() { if (showNametag) { namePlatePos = Camera.main.WorldToScreenPoint(transform.position + offset); namePlatePos.y = Screen.height - namePlatePos.y; PhotonView pView = GetComponentInParent<PhotonView>(); charname = (string)pView.owner.customProperties["charName"]; GUI.skin.label.richText = true; username = "<i>" + pView.owner.name + "</i>"; // italic GUI.Label(new Rect(namePlatePos.x, namePlatePos.y - 20, 200, 20), this.charname + "\n" + this.username, namePlatestyle); } } }

    Custom properties read from a Hashtable, so you make one and you can name it anything, here in this script I named it nameTag. Each hashtable can contain whatever group of information you want to send at one time. You might have a hashtable for your character's health that you'll want everyone to see, and maybe a more private hashtable for a list of their items that you only want sent to certain people if you're trading for example.

    ExitGames.Client.Photon.Hashtable nameTag = new ExitGames.Client.Photon.Hashtable();

    Next you'll add each value you want sent through the Add() function.

    nameOfHashTable.Add(key, value);
    nameTag.Add ("charName", charname);

    and then PhotonNetwork.SetPlayerCustomProperties() sets the values, basically making the hashtable ready to be sent to other players.

    PhotonNetwork.SetPlayerCustomProperties(nameTag);

    Make sure before you set your custom properties, that your value you added into the hashtable has already been set! Otherwise you're sending a null value. You can also call that function if your values have changed! If you haven't changed the values, there's no need to call it more than once.

    And of course, the rest of my script uses the value, and every player will have this, so that they know what to do with the value when they receive it. To get the value from other players, you have to retreive it through their PhotonView.

    variable = (type)PhotonView.owner.customProperties["key"];

    charname = (string)pView.owner.customProperties["charName"];

    That should provide different values for each person that everyone can see.

    My only problem I'm having with custom properties is that my hashtable is huge for character info. I'm sending names, colors of clothing, speed, and much more, and it backs up the Queue. You'll probably get a similar issue if you have a lot of data to send like I do, so watch this space for an answer soon on the best way to fix that if you get the same issue.
  • Tobias
    Options
    If you want (or have) to minimize the data in the properties, you should consider the following options:

    Use short(er) keys for the custom props. Using "cn" instead if "charName" is leaner to send.
    Aggregate settings which you change together. One key can have multiple values (an array). It's not as lean to change but leaner to send.
    Use byte or int values as shortcut and IDs for anything that can be listed. Character types, clothing, equipment, etc. A byte as value is leaner than a char. A array of bytes is leaner than a bunch of individual custom properties.
    The name per player is set as PhotonNetwork.playerName and available (as shown in the script above) as owner.name per PhotonView.

    If you have lots of game objects, at some point the count of props might go through the roof. Have an eye on that.
  • kittyLLLL
    Options
    That's interesting to know! Thank you Tobias. I redid my script according to your suggestions and that seems to have helped- I don't get any more hangups or errors at all anymore.
  • Tobias
    Options
    Cool. Thanks for the feedback.