-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Use VRCParentConstraint instead of constraint hack for world fixed objects when available #1326
Conversation
for world fixed objects when available
Editor/WorldFixedObjectProcessor.cs
Outdated
#if MA_VRCSDK3_AVATARS_3_7_0_OR_NEWER | ||
var isVrcAvatar = avatarRoot.TryGetComponent(out VRC.SDKBase.VRC_AvatarDescriptor _); | ||
|
||
if (isVrcAvatar) | ||
{ | ||
var constraint = obj.AddComponent( | ||
System.Type.GetType("VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint, VRC.SDK3.Dynamics.Constraint") | ||
) as VRC.Dynamics.ManagedTypes.VRCParentConstraintBase; | ||
constraint.IsActive = true; | ||
constraint.Locked = true; | ||
constraint.AffectsPositionX = true; | ||
constraint.AffectsPositionY = true; | ||
constraint.AffectsPositionZ = true; | ||
constraint.AffectsRotationX = true; | ||
constraint.AffectsRotationY = true; | ||
constraint.AffectsRotationZ = true; | ||
constraint.FreezeToWorld = true; | ||
} | ||
else | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer here to extract this logic to a method and swap out the method as a whole, rather than having an else block spanning an #endif
like this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK if the committed change is OK, it is hard to extract as a method because the case is "when VRCSDK with constraints is imported" (only can be filtered with #if
preprocessor) and "we are working on a VRChat avatar" (only can be checked with if (...) ... else
block)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking something like:
if (!TryGenerateVRChatConstraint(obj)) GenerateGenericConstraint(obj);
// ...
#if MA_VRCSDK3_AVATARS_3_7_0_OR_NEWER
bool TryGenerateVRChatConstraint(GameObject obj) { ... }
#else
bool TryGenerateVRChatConstraint(GameObject obj) { return false; }
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
It looks like the unit tests are broken now... |
Yes it requires changes on unit test, it is coded to check if I'm not very familiar on modifying unit tests, especially with such conditional flow. |
…fixed objects when available (#1326)" This reverts commit a984cf8. The prior behavior was to lock world fixed objects at their offset from the origin; however with this change we ended up locking them at a location relative to the avatar spawn location, breaking some gimmicks. I tried experimenting a bit with VRCConstraint to try to replicate this behavior, but it seems a bit non-trivial, so we'll revert this as a hotfix for now.
…fixed objects when available (#1326)" (#1363) This reverts commit a984cf8. The prior behavior was to lock world fixed objects at their offset from the origin; however with this change we ended up locking them at a location relative to the avatar spawn location, breaking some gimmicks. I tried experimenting a bit with VRCConstraint to try to replicate this behavior, but it seems a bit non-trivial, so we'll revert this as a hotfix for now.
As title indicates, this patches
WorldFixedObjectProcessor
to useVRCParentConstraint
instead of old-fashioned Unity constraint hack for world fixed objects, only when such components are available and we're working on VRChat avatars.