How can I evaluate a chooser in C++ and get it to output a struct and an array of animation assets ??

I want to do this in C++.
I think I need to use this function in ChooserFunctionLibrary.h :

UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe, BlueprintInternalUseOnly = “true”, DeterminesOutputType = “ObjectClass”))
static TArray<UObject*> EvaluateObjectChooserBaseMulti(UPARAM(Ref) FChooserEvaluationContext& Context,UPARAM(Ref) const FInstancedStruct& ObjectChooser, TSubclassOf ObjectClass, bool bResultIsClass = false);

but I am not able to figure out how. So, I guess I am asking for an example of how to use this function.
Or maybe there is another way of doing it. Either way, please help. Thanks.

Hi!

As an example, you can check out this:

void YourCustomEvaluateChooser(UChooserTable* Chooser, const FYourInputData& _InputData, FYourOutputData& _OutputData)
{
    if (!IsValid(Chooser)) return;

    const FInstancedStruct ResultInstances = UChooserFunctionLibrary::MakeEvaluateChooser(Chooser);
    FChooserEvaluationContext EvaluationContext;
    
    FInstancedStruct InputStruct;
    InputStruct.InitializeAs<FYourInputData>();
    FYourInputData& InputData = InputStruct.GetMutable<FYourInputData>();
    InputData = _InputData;
    EvaluationContext.Params.Add(InputStruct);
    
    FInstancedStruct OutputStruct;
    OutputStruct.InitializeAs<FYourOutputData>();
    FYourOutputData& OutputData = OutputStruct.GetMutable<FYourOutputData>();
    EvaluationContext.Params.Add(OutputStruct);
    
    TArray<UObject*> EvaluateObjects = UChooserFunctionLibrary::EvaluateObjectChooserBaseMulti(
        EvaluationContext,
        ResultInstances,
        UAnimMontage::StaticClass()
    );

    TArray<UAnimSequence*> Sequences;
    for (UObject* Object : EvaluateObjects)
    {
        if (UAnimSequence* Sequence = Cast<UAnimSequence>(Object))
        {
            Sequences.Add(Sequence);
        }
    }

    _OutputData = OutputData;
}
1 Like

Thank you for your help. I will test this. Thank you again

The code compiled but now I can’t open the animation blueprint anymore it just crashes

There is a function, that is doing exactly what this “Evaluate Chooser” node does:

/**
   * Evaluate a chooser table and return the list of all selected UObjects
   *
   * @param ContextObject         (in) An Object from which the parameters to the Chooser Table will be read
   * @param ChooserTable          (in) The ChooserTable asset
   * @param ObjectClass       (in) Expected type of result objects
   */
   UFUNCTION(BlueprintPure, meta = (BlueprintThreadSafe, BlueprintInternalUseOnly = "true", DeterminesOutputType = "ObjectClass"))
   static UE_API TArray<UObject*> EvaluateChooserMulti(const UObject* ContextObject, const UChooserTable* ChooserTable, TSubclassOf<UObject> ObjectClass);

It’s in UChooserFunctionLibrary class. To use it, you need to include “ChooserFunctionLibrary.h” and add “Chooser” module in your *.Build.cs file.

1 Like

This is the correct answer, but man, the file is a mess, and the way you add parameters is so confusing.