• RuntimesUnreal
  • SetupAttachment in real time

It looks like SetupAttachment in Unreal Engine 5 is not working as expected according to documentation

I have tried both Blueprint and C++ version of that functionality and I am curious whether I am doing something wrong or the runtime is.

The function "SetupAttachment" seems to correctly return True/False based on correctness of input data: whether the slot name and attachment name exist in skeleton data. Below are the images demonstrating the attempt (I've intentionally omitted C++ scenario to keep it cleaner):

Hand variations in Spine editor:

Default

Hand2

Please dont mind the aesthetics of hand2 - it is meant for a different pose. Here we are just assessing the possibility of using SetupAttachments in the future - for example to change a shirt or jacket, to show/hide sunglasses etc

Inside Unreal:

Blueprint

In-game result

Please mark that true is returned by the function, although the hand is not changed visually (the character is also flipped using SetScaleX - no errors or warnings encountered in the log).

Related Discussions
...

It seems like you are encountering issues with the SetupAttachment function in Unreal Engine 5, where it returns true but does not visually update the attachment. Based on the provided contexts, here are a few things to consider:

  1. Attachment in Setup Pose: Ensure that the attachment you are trying to set is correctly defined in the setup pose. As mentioned in the context, the setup pose attachment is specified by the slot, and all attachments not in a skin in the editor are found in the default skin at runtime.

  2. Order of Method Calls: The order in which methods are called can affect the outcome. For instance, calling SetSlotsToSetupPose after setting an attachment can overwrite your changes. Ensure that SetupAttachment is called at the correct point in your update cycle, preferably in LateUpdate or after all other updates.

  3. Skin and Slot Index: Verify that the slot and attachment names are correct and exist in the skeleton data. The slot index must match the attachment's slot index, as mismatched indices can cause issues.

  4. Runtime and Editor Differences: Sometimes, issues that do not appear in the editor can manifest in the runtime. Ensure that your project settings in Unreal are consistent with the editor settings, especially under Project Settings - Editor - Enter Play Mode Settings.

  5. Debugging: Add debug logs to check if the attachment is being set correctly. For example, log the attachment name and slot name before and after calling SetupAttachment to ensure they are as expected.

Here is a simplified example of how you might set an attachment in C++:

USpineSkeletonComponent* SkeletonComponent = ...; // Your skeleton component
FString SlotName = TEXT("hand");
FString AttachmentName = TEXT("hand2");

bool bSuccess = SkeletonComponent->SetAttachment(SlotName, AttachmentName);
if (bSuccess) {
    UE_LOG(LogTemp, Log, TEXT("Attachment set successfully"));
} else {
    UE_LOG(LogTemp, Error, TEXT("Failed to set attachment"));
}

Ensure that SkeletonComponent is valid and properly initialized.

If the issue persists, it might be worth checking if there are any known bugs or updates related to the Spine runtime for Unreal Engine 5.

Thank you for the reply. It looks like something indeed went wrong with the order of method calls - it is working now.