In Blueprint For loop, set nodes for TMap or TSet works like Add node.

Do I have to understand this intended?

You can download project files from :
https://github.com/cutycutyhyaline/UE4TMapAndTSetWithForLoop

Problem:

Here is a function. just Add number to TSet.

void ARep02GameModeBase::TSetTest(int32 InNumber, TSet<int32>& OutSet)
{
	OutSet.Add(InNumber);
}

With this, I made :

And run.

But, with TArray?

void ARep02GameModeBase::TArrayTest(int32 InNumber, TArray<int32>& OutArray)
{
	OutArray.Add(InNumber);
}

This frustrates me. Expecting consistency is too much?

Let’s dig more deeper.

This is Header:

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "Rep02GameModeBase.generated.h"

/**
 * 
 */
UCLASS()
class REP02_API ARep02GameModeBase : public AGameModeBase
{
	GENERATED_BODY()

	public:

	UFUNCTION(BlueprintCallable, Category = "Reproduce")
	void TArrayTest(int32 InNumber, TArray<int32>& OutArray);

	UFUNCTION(BlueprintCallable, Category = "Reproduce")
	void TMapTest(int32 InNumber, TMap<int32, int32>& OutMap);

	UFUNCTION(BlueprintCallable, Category = "Reproduce")
	void TSetTest(int32 InNumber, TSet<int32>& OutSet);	
};

And CPP:

// Copyright Epic Games, Inc. All Rights Reserved.


#include "Rep02GameModeBase.h"

void ARep02GameModeBase::TArrayTest(int32 InNumber, TArray<int32>& OutArray)
{
	OutArray.Add(InNumber);
}

void ARep02GameModeBase::TMapTest(int32 InNumber, TMap<int32, int32>& OutMap)
{
	OutMap.Add(InNumber, InNumber);
}

void ARep02GameModeBase::TSetTest(int32 InNumber, TSet<int32>& OutSet)
{
	OutSet.Add(InNumber);
}

And BP:

I know what “&” symbol means in cpp.
But… this is ridiculus because it works too honestly:(

Workaround?

What I could think is to make new local variable, and assign it to reference parameter.
(And I have to be careful to not forget this -_-)

void ARep02GameModeBase::TMapTestFixed(int32 InNumber, TMap<int32, int32>& OutMap)
{
	TMap<int32, int32> NewMap;
	NewMap.Add(InNumber, InNumber);
	OutMap = NewMap;
}

void ARep02GameModeBase::TSetTestFixed(int32 InNumber, TSet<int32>& OutSet)
{
	TSet<int32> NewSet;
	NewSet.Add(InNumber);
	OutSet = NewSet;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s