Facepunch / sbox-issues

176 stars 12 forks source link

`Collider.KeyframeBody.GetBounds()` is incorrect during the initialization Frame #6543

Open PolSpock opened 2 days ago

PolSpock commented 2 days ago

Describe the bug

Hi,

When you create a GameObject with ModelCollider and try to use ModelCollider.KeyframeBody.GetBounds(), it returns incorrect and overly large bounds instead of the actual bounds of the ModelCollider.

To Reproduce

1) Download https://github.com/Facepunch/sbox-scenestaging 2) Edit Gun.cs in the OnUpdate() method by adding:

if ( Input.Pressed( "Attack2" ) )
{
   var model = Model.Load( "models/sbox_props/wooden_crate/wooden_crate.vmdl" );

   var go = new GameObject();
   go.SetParent( Game.ActiveScene, false );

   var modelCollider = go.Components.Create<ModelCollider>();
   modelCollider.Model = model;

   var modelRenderer = go.Components.Create<ModelRenderer>();
   modelRenderer.Model = model;

   Log.Info( "before" );
   Log.Info( modelCollider.KeyframeBody.GetBounds() );

   await Task.DelayRealtimeSeconds( 0.1f );

   Log.Info( "after" );
   Log.Info( modelCollider.KeyframeBody.GetBounds() );
}

3) Start the networking.scene 4) Press Attack2 and check the console : Image

Expected behavior

KeyframeBody.GetBounds() should return the correct bounds immediately after the ModelCollider is created.

Media/Files

No response

Additional context

No response

aylaylay commented 2 days ago

Dirty colliders update next frame, I'll see if we can remove that limitation