Fragments (Extensibility)
Interaction fragments provide an extensibility mechanism for interactables without subclassing the widget or the player component.
What is a fragment?
A fragment is an instanced UObject stored on an interactable component:
UEDInteractableComponent::InteractionFragments
Base type:
UEDInteractionFragment(EditInlineNew,DefaultToInstanced)
Primary use case: UI extension ViewModels
When the player focuses an interactable actor, the player component:
- Clears extension ViewModels on the base
UEDInteractionViewModel - Iterates
InteractionFragments - Calls
OnInteractionStarted(...)on each fragment - If the fragment returns a
UMVVMViewModelBase*, it is registered as an extension ViewModel
This allows you to:
- Keep the base widget generic
- Provide custom per-interactable UI data without rebuilding the base ViewModel
Blueprint usage
- Create a Blueprint derived from
UEDInteractionFragment. - Implement
OnInteractionStarted. - Create and return a custom
UMVVMViewModelBase(Blueprint or C++) with the extra fields you need. - Add the fragment to
InteractionFragmentson your interactable actor.
C++ usage (pattern)
UCLASS()
class UMyInteractionFragment : public UEDInteractionFragment
{
GENERATED_BODY()
public:
virtual UMVVMViewModelBase* OnInteractionStarted_Implementation(UObject* Outer, UEDInteractionViewModel* BaseViewModel) override;
};
Return a ViewModel allocated with NewObject<UMVVMViewModelBase>(Outer, ...) so it has a stable outer and lifetime.