PlayerClothing.cs

Component attached to a player that applies avatar clothing to a SkinnedModelRenderer. On start it reads the owner's stored "avatar" userdata, deserializes it into a ClothingContainer, then updates and applies that appearance via a Dresser tied to the model renderer.

Networking
using Sandbox;

public sealed class PlayerClothing : Component
{
	[Property] public SkinnedModelRenderer Body { get; set; }

	protected override void OnStart()
	{
		ApplyAvatarClothing();
	}

	public void ApplyAvatarClothing()
	{
		if ( Body == null ) return;

		
		var connection = Network.Owner ?? Connection.Local;
		if ( connection == null ) return;

		var clothing = new ClothingContainer();

		
		var avatarJson = connection.GetUserData( "avatar" );
		if ( !string.IsNullOrEmpty( avatarJson ) )
		{
			clothing.Deserialize( avatarJson );
		}

	
		var dresser = Dresser.GetOrCreate( Body );
		dresser.UpdateAppearance( clothing );
		dresser.Apply( clothing );
	}
}