DragControls causes lag v2

Hi, I have a simple code snippet that allows selecting parts of my model when clicked. However, I’m encountering an issue where input is delayed or sometimes doesn’t register at all for certain models.

Using the profiler, I found that the problem seems related to the DragControls on onDragStart, particularly the expandByObjectRecursive function. This issue appears more noticeable with complex models, and it doesn’t occur when the models are compressed, suggesting the complexity of the model might be the root cause.

Could you check if this might be similar to the onPointerMove drag controls issue we discussed earlier? If needed, I can provide a bug report or profiler trace for further details.

Hello Vydymil,

The issue you are experiencing with DragControls potentially causing lag is indeed something that can occur with complex models, especially if the expandByObjectRecursive function is involved. This function is likely being called for every drag event, and if the model is composed of many objects, this can introduce significant delays.

In your case, since you notice the issue primarily with complex models, you may want to consider the following suggestions to mitigate the lag:

  1. Optimize Your Model: Reduce the polygon count of your models, or use simpler models for dragging operations, especially if they contain many nested objects.

  2. Control Event Frequency: Implement a throttling mechanism to limit how often drag-related calculations are performed, especially for the onDragStart or onPointerMove events.

  3. Debug Logging: Use console logging to track the performance of the expanding or hit detection. This can help you pinpoint whether specific models or areas of code introduce delays.

  4. Profile the Function: Since you mentioned using the profiler, keep an eye on calls to expandByObjectRecursive and see if caching previous calculations can help reduce redundant calls.

  5. Review DragControls Settings: Experiment with different DragMode settings. For instance, switching to Attached during dragging instead of allowing complex behavior might improve responsiveness.

If you’d like, I can help you further optimize your DragControls implementation based on your specific use case or provide more direction on refactoring if necessary. If you have profiler traces or specific debug outputs, sharing those could also assist in diagnosing the problem deeper.

Feel free to ask further questions to clarify or provide additional details!

1 replies left - Get a PRO license for more AI replies.
thread_ATg5GUDOX2eehLpoG1nHlpdc
Reply to this message to continue the conversation

Hello, just to be sure: which engine version are you currently using?

4.1.0-alpha.4

I just updated to the latest version, but the issue still persists.

Could you send another bugreport please with steps on how to reproduce the issue? Thank you :slight_smile:

Just sent it. If there are any problems with the scene, just let me know.

Hello

the top part of the flower mesh has 550k vertices - when running compression we will automatically create mesh LODs for you but you need to enable AutoCompression if you need automatic LODs for your development server.

You have multiple options to improve this if enabling compression for your dev server is not an option:

A) You can optimize the model and manually create LODs
B) You can set the blossom to the IgnoreRaycast layer in Unity and add a invisible proxy mesh as a child that you use instead for raycasting
C) You could add collider meshes (e.g. BoxCollider) and use the physics.engine.raycast

I hope that helps