.gen.cpp keeps adding a '&' to a function parameter

Shown below is the function and below that is version that is being generated in the .gen.cpp file. If I delete the ‘&’ out it compiles fine, but every time I make a change to this class it adds it back in and it’s driving me slightly mad.

Can anyone shed any light on this?
Screenshot 2025-02-12 195829

Question: Why are you editing the .gen file? It is generated by the engine automatically adding extra optimizations.

Passing a TArray without a reference symbol & you would be making a copy of the whole array each time you would call CreateGrid.

the character list is also a const => so it is unchangeable from within the function, so any changes will not be reflected outside of the function.

So you will basically throw away the copy of the array after the function. The only way you could use it is to extract data from the characters inside the function.

Basically it’s a memory optimization added by the engine to not bloat your memory usage :wink:

It’s an array of 3 items called once per game. There isn’t any real overhead being created here.

I’m a little confused why this optimisation is only being done when the function is blueprint native. It handles the array fine otherwise.

I can create a blueprint function that does exactly this, so why limit my options in this instance?

try this in the header

	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Combat Hex Grid")
	void CreateGrid(UDataTable* DataTable, UPARAM(ref) const TArray<ABasePartyCharacter*> &CharacterList);

const is optional but it’s more optimized if the compiler knows that characters won’t be changed in the function

in cpp

void ACombatHexGrid::CreateGrid_Implementation(UDataTable* DataTable, UPARAM(ref) const TArray<ABasePartyCharacter*> &CharacterList)
{
}

That way you get this in bp

And the override