Kehom / GodotAddonPack

A collection of pure GDScript addons for Godot
http://kehomsforge.com
MIT License
189 stars 15 forks source link

[Network] Player custom property #16

Closed yuraj11 closed 4 years ago

yuraj11 commented 4 years ago

Is it possible to retrieve custom property for all players? Does server sync custom properties of all players? Because I can't get this working. I have something like this:

network.player_data.add_custom_property("character_skin", "default", NetCustomProperty.ReplicationMode.ServerBroadcast)

in game menu I am setting the property type as string:

network.player_data.local_player.set_custom_property("character_skin", skin)

in player script I have this:

func _physics_process(delta: float) -> void:
if corrected_state != null:
 if !initialized:
  var skin = network.player_data.get_pnode(meta_uid).get_custom_property("character_skin")
  # set skin
  initialized = true

I can set skin as another variable for syncing in snapshot class but I don't want to do this because it doesn't make sense to sync skin everytime but only once.

Kehom commented 4 years ago

Well, the delta snapshot compression does not replicate unchanged properties.

Regardless, the ServerBroadcast setting should send the property to everyone. In your case, maybe the moment you are initializing the packet containing the update hasn't arrived yet. One important thing to note about custom properties is that it uses the reliable channel, meaning that it may take more time than the other synchronization packets. That said, there is one event that is emitted by the network system precisely to notify about custom property updates. The signal itself is custom_property_changed(pid, pname, value) In here: pid is the player ID owning the changed property pname is the name of the property value is the new value of the property.

yuraj11 commented 4 years ago

custom_property_changed is never called for me :/

Kehom commented 4 years ago

Just to make sure things are working, could you please test this event through a singleton? I realize it's probably not a really nice place to listen to the event, but if it works there I may think about a way to make this event occur when the client notifies it is ready to start receiving synchronization data.

yuraj11 commented 4 years ago

I have tried adding it into singleton but it's still not working. Also tried it in my demo I previously send you and same result.

Kehom commented 4 years ago

OK. Thank you. This means there is a bug with the system. Will investigate it.

yuraj11 commented 4 years ago

image there's still something wrong - I have checked your demo but only server has all values correct. The clients have somehow wrong mixed values. When a new player is connected it should propagate properties of all players (including server) to the newly connected client.

Kehom commented 4 years ago

Oh well. I knew the "server broadcast" mode would be more problem than I thought!

yuraj11 commented 4 years ago

Thanks. Works!