New definition; multiple initialisation

Hey there!

I’ve just update a project from Unreal 5.4.4 to 5.5.1. When I’ve compiled it I’ve got the following error:

Error C2374 ‘NextFallingBlockSpawnLocation’: new definition; multiple initialisation C:\source\Tetris\Public\GameModeBase.h 14		
Error C2374 ‘NextBlockSampleSpawnLocation’: new definition; multiple initialisation C:\source\Tetris\Public\GameModeBase.h 15

I have two header files with these declarations.

In TTetrisGameModeBase.h:


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

#pragma once

#include "CoreMinimal.h"
#include "TUtils.h"
#include "GameFramework/GameModeBase.h"
#include "TTetrisGameModeBase.generated.h"

class ATFallingBlockActor;
class ATCheckLinesActor;

const FVector PuzzleToSolveSpawnLocation = FVector(0.0f, -500.0f, 850.0f);
const FVector NextFallingBlockSpawnLocation = FVector(0.0f, 25.0f, 1000.0f);
const FVector NextBlockSampleSpawnLocation = FVector(0.0f, -850.0f, 850.0f);

/**
 * 
 */
UCLASS()
class TETRIS_API ATTetrisGameModeBase : public AGameModeBase

And in TProgrammingModeBase.h:

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

#pragma once

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

enum class EInstruction : uint8;
class ATCheckLinesActor;
class ATFallingBlockActor;
enum class EBlockType : uint8;

const FVector NextFallingBlockSpawnLocation = FVector(0.0f, 25.0f, 1000.0f);
const FVector NextBlockSampleSpawnLocation = FVector(0.0f, -850.0f, 850.0f);
const FVector CreatedInstructionSpawnLocation = FVector(0.0f, -600.0f, 150.0f);

/**
 * 
 */
UCLASS()
class TETRIS_API ATProgrammingModeBase : public AGameModeBase

I don’t know why I’m getting these errors because these header files don’t reference each other.

Any idea?

Thanks.

Hey,

This looks to be because you are defining 2 Global variables with the same name. You either want to change these so they arent named the same or change them not to be global and instead move them to be part of a class or namespace.

As Jake-Simpson said, you have two variable declarations visible from the same scope.

Either you can just have the
const FVector XXX = FVector( ... ); in the header (leave it out of the cpp)

or you can extern a declaration in the header:
TETRIS_API extern const FVector XXX;
with the definition in the cpp:
`const FVector XXX = FVector( … );

Lastly you could shift those variables to public static members of your game mode so that they don’t pollute the global namespace:

In the header:
static const FVector XXX;
In the cpp:
const FVector ATProgrammingModeBase::XXX = FVector( ... );