Hi everyone,
I’m currently implementing a custom SmartObjectUserComponent
that allows non-character actors (like props) to claim and interact with Smart Object slots.
My current approach stores all FSmartObjectClaimHandle
s in an internal array inside the user component. This allows me to keep track of what the user has claimed, and later decide whether to occupy or free a slot.
Here’s a simplified version of the relevant logic:
UPROPERTY()
TArray<FSmartObjectClaimHandle> ClaimHandles;
FSmartObjectClaimHandle ClaimSlot(const FSmartObjectSlotHandle& SlotHandle)
{
const FSmartObjectClaimHandle Handle = Subsystem->MarkSlotAsClaimed(...);
if (Handle.IsValid())
{
ClaimHandles.Add(Handle);
}
return Handle;
}
bool FreeSlot(const FSmartObjectClaimHandle& Handle)
{
if (Subsystem->MarkSlotAsFree(Handle))
{
ClaimHandles.Remove(Handle);
return true;
}
return false;
}
I also attach a custom FSmartObjectSlotStateData
to the slot with a weak reference to the user component, so the slot can still access the user if needed.
My question is:
Is this a good practice? Should the Smart Object user component be responsible for storing references to all claimed slot handles? Or is it better to treat claiming as fire-and-forget and rely solely on the slot’s internal state data?
I’m especially concerned about lifetime management and proper cleanup when the user component is destroyed.
Any insights or suggestions from those with experience in Smart Objects would be appreciated!
Thanks in advance!