Yes, it is possible to control the visibility of slots and attachments programmatically in both Unity and Unreal Engine. Here are the steps and considerations for each:
Unity
Setting Attachments to Null: You can set an attachment to null
to hide it. This can be done every frame after the animation has been applied to ensure that the animation does not override your changes.
slot.Attachment = null;
Using SkeletonAnimation.UpdateComplete
: You can use the SkeletonAnimation.UpdateComplete
callback to set attachments after the animation has been applied.
skeletonAnimation.UpdateComplete += delegate {
slot.Attachment = null; // or set to a specific attachment
};
Avoid Keying Attachments in Animations: Ensure that your animations do not key the attachments you want to control via code. This prevents the animation from overriding your code changes.
Unreal Engine
Setting Attachments to Null: Similar to Unity, you can set an attachment to null
to hide it.
slot->SetAttachment(nullptr);
Using Update Callbacks: You can use update callbacks to set attachments after the animation has been applied.
skeletonAnimation->OnUpdateComplete.AddDynamic(this, &YourClass::OnUpdateComplete);
Avoid Keying Attachments in Animations: Ensure that your animations do not key the attachments you want to control via code.
General Considerations
- Skins: Use skins to manage different sets of attachments. This can simplify the process of showing/hiding attachments.
- Setup Mode: Use the setup mode to define the default state of your slots and attachments, and reset to this state when needed.
- Performance: Ensure that your code changes are efficient and do not introduce performance issues by making unnecessary changes every frame.
By following these steps, you can programmatically control the visibility of slots and attachments, making your workflow simpler and more efficient.