Not possible with a function in BP
You can use a macro instead, which should work as expected, but can’t be called from outside of this BP
Similar problem here:
Select Node with Set Array Element - Programming & Scripting / Blueprint - Epic Developer Community Forums (unrealengine.com)