NetworkHelper doesn't sync

Started by bosinn · 4 months ago · 2 replies · 154 views

This thread has been marked as solved
Resolved by garry · 4 months ago
edited 4 months ago#1
bosinn
Member
JoinedDec 2023 Posts9 Score35
I've placed spawn points, added NetworkHelper component, selected player prefab which is basically stock player component, pressed play button in editor and then pressed "Join via new instance"

I've moved around between two instances and position with clothes doesn't synchronize. Is it bug or I'm doing something wrong?

#2
bosinn
Member
JoinedDec 2023 Posts9 Score35
Don't know what happened. I've recreated scene, placed player controller and made it prefab, placed prefab in "Network Helper" and it worked. Cloth still doesn't sync. I've patched "Network Helper" class to use ClothingContainer:
public void OnActive( Connection channel )
{
    Log.Info( $"Player '{channel.DisplayName}' has joined the game" );

    if ( !PlayerPrefab.IsValid() )
       return;

    //
    // Find a spawn location for this player
    //
    var startLocation = FindSpawnLocation().WithScale( 1 );

    // Spawn this object and make the client the owner
    var player = PlayerPrefab.Clone( startLocation, name: $"Player - {channel.DisplayName}" );

    // Assume that if they have a skinned model renderer, it's the citizen's body
    if ( player.Components.TryGet<SkinnedModelRenderer>( out var body, FindMode.EverythingInSelfAndDescendants ) )
    {
       var clothing = new ClothingContainer();
       clothing.Deserialize( channel.GetUserData( "avatar" ) );
       clothing.Apply( body );
    }
    
    player.NetworkSpawn( channel );
}
#3
gasleet
Member
JoinedAug 2024 Posts78 Score6,923
I had a similiar problem with the clothing of the players not working properly. Someone was always naked.
I've fixed this by using the INetworkSpawn interface and applying the dresser. Atleast I think i fixed it...
public sealed class MyComponent : Component, Component.INetworkSpawn
{
	public void OnNetworkSpawn( Connection connection )
	{
		dresser.Clear();
		dresser.Apply();
	}
}
check_circle garry marked this thread as solved 4 months ago
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.