Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skinned mesh renderer lags behind #5484

Closed
SwagAccount opened this issue May 9, 2024 · 9 comments
Closed

Skinned mesh renderer lags behind #5484

SwagAccount opened this issue May 9, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@SwagAccount
Copy link

SwagAccount commented May 9, 2024

Describe the bug

I am moving an object using my follow attachment script.
As a child the object has an arm which uses a skinned mesh renderer.

That mesh renderer and any other skinned mesh renderers as a child will always lag behind. In the scene view this doesn't occur

To Reproduce

  1. Move an object using pre render
  2. Have a child with a skinned mesh renderer
  3. Do the hanky panky

Expected behavior

Not lagging behind

Media/Files

https://github.com/SwagAccount/the_second_coming_of_k/blob/main/code/FollowAttachment.cs

https://github.com/Facepunch/sbox-issues/assets/160753124/36c24333-efbf-4deb-80b5-52d698b4b302
^ I have also attached a normal model to show its not the script that is lagging behind.

Additional context

No response

@SwagAccount SwagAccount added the bug Something isn't working label May 9, 2024
@garrynewman
Copy link
Member

Does the same occur if you do it in OnUpdate?

@garrynewman garrynewman self-assigned this May 9, 2024
@SwagAccount
Copy link
Author

Yes, ive tried all updates

@SwagAccount
Copy link
Author

I've now changed my system so the arms attach to the camera and the ik is to move the hand to the gun, still the same effect.

@PolSpock
Copy link

PolSpock commented May 9, 2024

Hi,

Since this commit, i guess cause i didn't have this issue yesterday,
it looks like the GetAttachment position is now incorrect during the first tick :

image
image

I am currently investigating to find a scenario to reproduce the issue. I will edit this comment

Edit :

  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:
2024-05-09.19-17-55.mp4

@garrynewman
Copy link
Member

I made a change that should fix the first frame being wrong position.

This won't fix the OP request though. This is a chicken and egg problem, and the only way I can see to fix it would be to allow you to set IK bones to offsets from GameTransforms.

@PolSpock
Copy link

PolSpock commented May 10, 2024

I made a change that should fix the first frame being wrong position.

This won't fix the OP request though. This is a chicken and egg problem, and the only way I can see to fix it would be to allow you to set IK bones to offsets from GameTransforms.

Nothing change for the sub issue (my build id : 14327656), i have created a issue in order to stop off topic for this issue : #5493

@SwagAccount
Copy link
Author

Is there a reason that the skinned mesh renderer is updating after the camera, that is the only understandable thing that is happening. I can make any normal model renderer I want follow something by setting the position and it's perfect, but as soon as I change the model renderer to a skinned renderer it lags a frame behind.

@SwagAccount
Copy link
Author

Ok strange thing happening. When I move the gun around it leaves a ghost of an arm that is perfectly connected to the gun, how I want, whilst the rest of the arm is stuck a frame behind. However, when I record it the ghosting doesn't appear in the recording. What on earth is happening.

@SwagAccount
Copy link
Author

Ok, solved the issue by using SetIK and using the correct naming for parameters in anim graph.
https://cdn.halend.dev/retro/1105/sbox-dev_1xz8x0h9y0.png
if ( IkRightHand.IsValid() && IkRightHand.Active ) Target.SetIk( "hand_right", IkRightHand.Transform.World ); else Target.ClearIk( "hand_right" );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants