Events are not raised correctly
Options
Drakce
✭
in Photon Bolt
I don't know what happens but if I send few events quickly this happens:
As you can see in the image, data is received correctly but when bolt tries to raise these events, data just get's messed up ( does not match received data ). I'm so confused right now.
As you can see in the image, data is received correctly but when bolt tries to raise these events, data just get's messed up ( does not match received data ). I'm so confused right now.
0
Best Answer
-
It looks like the problem has to do with sending too many entity events at the some time with a lot of data. As you can see here http://doc.photonengine.com/en/bolt/current/reference/events
entity events are unreliable and shouldn't be used for something important like items for a chest. Global events are what should be used for anything important.5
Answers
-
Can you paste your code here?0
-
Code for sending events, really nothing special... I even implemented small delay.
using UnityEngine; using System.Collections; public class InventoryChest : Bolt.EntityEventListener<IChestInventoryState>, InventoryInterface { protected BoltEntity OpenedBy; protected bool ChestOpened = false; public delegate void OnInventoryChanged(); public event OnInventoryChanged OnInventoryChangedEvent; public int Slots; public iItem[] Items { get; set; } public Transform GetDropPoint { get { return transform; } } public int ItemsLength { get { return Slots; } } protected bool ChestAttached = false; public void SetItem(int index, int id=-2, int amount=-2, float durability=-2, bool SendChangeEvents = true) { if (entity.isOwner) { //Only if owner, update must be immidiate if(id != -2) Items[index].ID = id; if (amount != -2) Items[index].Amount = amount; if (durability != -2) Items[index].Durability = durability; if (SendChangeEvents && OnInventoryChangedEvent != null) OnInventoryChangedEvent.Invoke(); if (OpenedBy != null && ChestOpened) { ChestSlotFixEvent fixi = ChestSlotFixEvent.Create(OpenedBy, Bolt.EntityTargets.OnlyController); fixi.Slot = index; fixi.Amount = Items[index].Amount; fixi.ID = Items[index].ID; fixi.Durability = Items[index].Durability; fixi.Send(); } } } public SlotBase GetSlot(int index) { return InventoryManager.Instance.Chest.Slots[index]; } void Start() { //create player inventory, 36 in size Items = new iItem[Slots]; } public override void OnEvent(ClientToServerRequest evnt) { if (evnt.Request == 2) { //Requested opening of the chest if (!ChestOpened) { ChestOpened = true; OpenedBy = evnt.RaisedBy.GetPlayer().entity; StartCoroutine(UpdateForTheFirstTime()); } } } public IEnumerator UpdateForTheFirstTime() { for (int i = 0; i < Slots; i++) { SetItem(i, -2, -2, -2); yield return new WaitForSeconds(0.05f); } } public override void OnEvent(SlotFixEvent evnt) { base.OnEvent(evnt); } public iItem GetItem(int index) { return Items[index]; } /// <summary> /// Entity set up done. /// </summary> public override void Attached() { ChestAttached = true; //Initialize values if (entity.isOwner) { for (int i = 0; i < Slots; i++) { Items[i].ID = -1; Items[i].Amount = 0; } } } }
This is code for receiving events, it's part of the player script which is derived from entity listener.public override void OnEvent(ChestSlotFixEvent evnt) { var oinv = InventoryManager.Instance.OpenedInventory; oinv.Items[evnt.Slot].ID = evnt.ID; oinv.Items[evnt.Slot].Amount = evnt.Amount; oinv.Items[evnt.Slot].Durability = evnt.Durability; }
0 -
It looks like a lot of code you reference is missing, can you upload a repro project?0
-
No, I can't do that. But I'll just create a simple test app and see if this happens there,0
-
If it happens there you can upload it and send to me (repro project is just a small project that reproduces the behavior you're having)0
-
Here is the simple script without any references and I tested it in a fresh project. Guess what problem / bug is still there:
using UnityEngine; using System.Collections; public class CubeEvents : Bolt.EntityEventListener<ICubeState> { //THIS IS DATA THAT ALL SHOULD RECEIVE int key = 9; public override void SimulateOwner() { if (Input.GetKeyDown(KeyCode.Space)) { for (int i = 0; i < 30; i++) { var evnt = CustomEvent.Create(entity, Bolt.EntityTargets.OnlyController); int pass = i + key; evnt.DATA1 = i; evnt.DATA2 = pass; //Even more data sent across evnt.DATA3 = i % 2 == 0; evnt.DATA4 = i.ToString(); //Send evnt.Send(); } } } public override void OnEvent(CustomEvent evnt) { int num = (evnt.DATA2 - key); if (evnt.DATA1 != num) { Debug.LogError("KEY DO NOT MATCH??"); } } }
I'll send you whole project once it uploads.0 -
Here is the project:
https://www.dropbox.com/s/0yhsggbjc209ri5/testApp.rar?dl=00 -
Also one more thing, I kinda commented script wrong. But you should see what's actually going on0
-
I added entity.TakeControl(); to the cube attach so it would stop giving warnings, then added the cube to the Game scene, I don't see any problems0
-
Control is given in servercallbacks script when scene is loaded remotely. So server is not a player.
In order to see a problem, run a server and a client. Press spacebar in order to run events (pess spacebar few times quickly) and the error will show up in the client.
Oh and one more thing, you need to enable script debuging when building client to see the actual error.0 -
It looks like the problem has to do with sending too many entity events at the some time with a lot of data. As you can see here http://doc.photonengine.com/en/bolt/current/reference/events
entity events are unreliable and shouldn't be used for something important like items for a chest. Global events are what should be used for anything important.5 -
Hm, I'll try with global events.
But why event is received and failed to be raised?
0 -
Also one more thing, out of 30 events about 3-4 are raised. Doesn't that sounds broken?0
-
Raised means the event is sent. In the project you uploaded it looks like 30 events were sent and received.0