sbox-issues icon indicating copy to clipboard operation
sbox-issues copied to clipboard

`GetAttachment` wrong position at first frame

Open PolSpock opened this issue 9 months ago • 5 comments

Describe the bug

Hi,

Since this commit, i guess cause i didn't have this issue before, Even if the recent garry's attempt fix hasn't worked

it looks like the GetAttachment position is now incorrect during the first tick :

image image

To Reproduce

  1. Create GameObject parented to the head bone :
var goHat = new GameObject();
goHat.SetParent( bodySkinnedModelRenderer.GetBoneObject( bodySkinnedModelRenderer.Model.Bones.AllBones.Where( x => x.Name.Equals( "head" ) ).FirstOrDefault() ));
goHat.Components.Create<MyAttachment>();
  1. Create MyAttachment Component:
public class MyAttachment : Component
{
	[Property] public SkinnedModelRenderer SkinnedModelRenderer { get; set; }

	public SkinnedModelRenderer GetPlayermodel()
	{
		return GameObject.Components.GetInAncestors<SkinnedModelRenderer>();
	}

	protected override void OnStart()
	{
		base.OnStart();

		SkinnedModelRenderer ??= GameObject.Components.GetOrCreate<SkinnedModelRenderer>();

		var model = Cloud.Model( "darg/santahatprop" );
		SkinnedModelRenderer.Model = model;

		Transform.Position = GetPlayermodel().GetAttachment( "hat" ).Value.Position;
		Transform.Rotation = GetPlayermodel().GetAttachment( "hat" ).Value.Rotation;

	}

	protected override void OnUpdate()
	{
		base.OnUpdate();

		// TOGGLE COMMENT / UNCOMMENT
		//Transform.Position = GetPlayermodel().GetAttachment( "hat" ).Value.Position;
		//Transform.Rotation = GetPlayermodel().GetAttachment( "hat" ).Value.Rotation;
	}
}
  1. See bug OnStart:

https://github.com/Facepunch/sbox-issues/assets/5229571/f58d636b-9a6b-4205-8238-9625e87e2af6

Expected behavior

Always getting the correct position of the GetAttachment()

Media/Files

No response

Additional context

BuildId : 14327656

PolSpock avatar May 10 '24 15:05 PolSpock