Download

Misbehaving GENERATED_BODY(), arrays and referencing

Eyoo, I’m currently learning C++ in order to write custom blueprints (worked with R and MatLab before, C++ is new to me) and I’m having some issues with two things- GENERATED_BODY() generally being the line upon which many errors take place, and not understanding the actual meaning and use of pointers and references.

As further explanation, this code is the header for two sets of code that are both intended to input an array on one side, alter it within the code using the other input variables as constants, and then either output an array I can then set (which is what this currently does) or overwrite the values of the old array (which was what I did with the blueprint prototyping of this code).

So, questions-


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ProcGenSculpts.generated.h"

/**
 * 
 */
UCLASS()
class SAUROBOROSPROTC_API UProcGenSculpts : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()
        UFUNCTION(BlueprintCallable, BlueprintPure, Category = "ProcGenSculpts")
        static void CreateFlatHeightMap(UPARAM(ref) TArray<int32>& HeightMapArray, TArray<int32>& HeightMapArrayRef, const int32 AddedToXAxis, const int32 AddedToYAxis, 
            const int32 BaseHeight);
        UFUNCTION(BlueprintCallable, Category = "ProcGenSculpts")
        static void FillHeightMap(UPARAM(ref) TArray<FName>& MapTileArray, TArray<FName>& MapTileArrayRef, const TArray<FName> TileOptions1, const TArray<FName> TileOptions2, 
            const TArray<FName> TileOptions3, const TArray<FName> TileOptions4,    const TArray<FName> TileOptions5, const TArray<int32> HeightMapArray, const int32 AddedToXAxis, 
            const int32 AddedToYAxis, const int32 LevelSeed);

};


-The GENERATED_BODY() is generating an error explaining that ‘no suitable user-defined conversion from “TArray<int32, FDefaultAllocator>” to “TArray<FName, FDefaultAllocator>” exists’. This is confusing, because the only thing interacting with both int32 arrays and FName arrays is the UPARAM(ref). Why is the error over here, and is it an error due to misunderstanding GENERATED_BODY(), due to misunderstanding UPARAM(ref), or for some entirely unexpected reason?

-I’d like the code to scale upwards well- is


static void func(UPARAM(ref) TArray<type>& ArrayName, TArray<type>& ArrayNameRef) 

a reasonably efficient way of doing things, or is there a better habit to get into?

-Does anyone know any step-by-step tutorials to &, *, . and -> that showcase how they act in different scenarios, as opposed to stating their mechanics? I usually interpret things more easily when I start at how it’s used and understand why that’s the case.

Thank you for any assistance that can be offered <3