Skip to content

Implementing fixes for Unity 2021.3 LTS #4

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ByteSz
Copy link

@ByteSz ByteSz commented Mar 8, 2025

Addressed main issues brought up so far related to working in Unity 2021.3 and from a fresh download.

Changelog:

  • Replaces "GetOrAddComponent" extension calls with base "GetComponent" & "AddComponent" function calls
  • Implemented an alternative replacement for "Gizmos.DrawLineList" by using "Gizmos.DrawLine" in existing foreach loop

Closes #2
Closes #3

@ByteSz ByteSz marked this pull request as ready for review March 8, 2025 01:32
@HunterProduction HunterProduction self-requested a review March 12, 2025 08:41
Copy link
Owner

@HunterProduction HunterProduction left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a little comment on the implementation, suggesting a small improvement to the fixes

Gizmos.color = Color.blue;
Gizmos.DrawLineList(points);
//Draw gizmo line for connections
Gizmos.DrawLine(points[i], points[i++]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem with index increment in this loop. Calling i++ will already increment the index after the instruction is completed.

// Here i == 0
points[i++] = centerOfMass;
// Here i == 1
points[i++] = otherCenterOfMass;
// Here i == 2
Gizmos.DrawLine(points[i], points[i++]);

Here is the problem. We should link with a line points[0] and point[1], but index is already been incremented so we are probably skipping array elements. The following index management should be more robust.

points[i] = centerOfMass;  
points[i + 1] = otherCenterOfMass; 
Gizmos.DrawLine(points[i], points[i + 1]); 
i += 2;

By the way, I used DrawLineList since it's declared to be a more optimized method to draw multiple lines in a raw, so I think we should keep it for newer versions of Unity, and add this fix as an optional code with a condition at compile time checking for the Unity version:

#if UNITY_2023_1_OR_NEWER
// We can use the version with DrawLineList
#else
// We can use the one with simple DrawLine
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants