How to use a smart object in c++ 5.1

How Do you use a claimed Smart object in c++, I can’t find an example anywhere online.

I currently have everything in place to claim the smart object successfully, but it refuses to run. My AI will not move to the smart object and use it, but it’s only from the c++ function. If i call the BP node it works which i tested by calling an interface function that is simply calling the BP node version.

Help would be fantastic here.
Proof that claim is valid:

if (USmartObjectBlueprintFunctionLibrary::IsValidSmartObjectClaimHandle(Claim))
{
	UE_LOG(LogTemp, Warning, TEXT("Smart Object Claimed"));

Interface Function which calls the node in BP and it runs.

 /* Test for valid claim using Interface. This runs fine 
if (ContextActor->GetClass()->ImplementsInterface(UBPI_NPCDynamicAI::StaticClass()))
{
UE_LOG(LogTemp, Warning, TEXT("Running Interface"));				IBPI_NPCDynamicAI::Execute_RunClaimedEvent(ContextActor, Claim);
}
*/

The actual code that doesn’t work:

UAITask_UseGameplayBehaviorSmartObject::UseClaimedGameplayBehaviorSmartObject(Controller, Claim, true);

//These don't work either 
//UAITask_UseGameplayBehaviorSmartObject* Task;
//Task->UseClaimedGameplayBehaviorSmartObject(Controller, Claim, true);
1 Like

Figured it out, for anyone trying to do this in the future here are the ancient texts you seek:

Make sure you have all the necessary modules and includes. In 5.2+ it appears there’s a new function MoveAndUseClaimedGameplaySmartObject that works the same, but the only thing you need to do is this:

UAITask_UseGameplayBehaviorSmartObject::UseClaimedGameplayBehaviorSmartObject(Controller, Claim, true)->ReadyForActivation();

The ReadyForActivation() is all that was missing.

2 Likes

For Anyone else who may see this in the future as of 5.1 - 5.3 the delegates for completion and failure binding are protected and can’t be accessed from outside classes unless you hack your way through it. You’re probably better off just using the function in blueprint…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.