# Variable already defined when UPROPERTY is used

**URL:** <https://forums.unrealengine.com/t/variable-already-defined-when-uproperty-is-used/30259>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 16, 2015, 1:08pm UTC](https://forums.unrealengine.com/t/variable-already-defined-when-uproperty-is-used/30259 "2015-05-16T13:08:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_0cd3b792](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0cd3b792](https://forums.unrealengine.com/u/anonymous_user_0cd3b792)\
**Post date:** [May 16, 2015, 1:08pm UTC](https://forums.unrealengine.com/t/variable-already-defined-when-uproperty-is-used/30259/1 "2015-05-16T13:08:22Z")

</div>

Hi all!

I have this header:

```auto

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

#pragma once

#include "Components/ActorComponent.h"
#include "MovementHelper.generated.h"

USTRUCT(BlueprintType)
struct FMovementFlags
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goForward;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goBackwards;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goLeftyards;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goRightwards;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goUp;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Movement flags")
    bool goDown;
};

USTRUCT(BlueprintType)
struct FRotationFlags
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Rotation flags")
    bool rotateUp;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Rotation flags")
    bool rotateDown;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Rotation flags")
    bool rotateLeft;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper|Rotation flags")
    bool rotateRight;
};

/**
* This component allows to move and rotate an actor very easily at a fixed speed.
*
* Jumping is managed by the CharacterMovementComponent, so, if you want to jump,
* you should add this component to a Character actor.
*
* If this actor is a Pawn (or derived), you can also use Pawn AddMovementInput,
* AddControllerPitchInput, AddControllerRollInput and AddControllerYawInput
* methods if you want a more gradual movement.
*
* To use these, you'll need to create axes in the project's settings.
*/
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class UMovementHelper : public UActorComponent
{
	GENERATED_BODY()

public:
    **// Flags for actor movement
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper")
    FMovementFlags movementFlags;

    // Flags for actor rotation
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Helpers|Movement Helper")
    FRotationFlags rotationFlags;**

    // The speed at which the actor will rotate
    UPROPERTY(BlueprintReadWrite, Category = "Movement")
    float moveSpeed;

    // The speed at which the actor will move
    UPROPERTY(BlueprintReadWrite, Category = "Movement")
    float rotateSpeed;

    // Sets default values for this component's properties
	UMovementHelper();

	// Called when the game starts
	virtual void InitializeComponent() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

    // Makes this actor jumping. Only works if the actor is a character
    UFUNCTION(BlueprintCallable, Category = "Movement")
    void Jump();
};

```

And i have a problem with the lines in bold.

If i remove the UPROPERTY macro from movementFlags and rotationFlags variables, everything compiles fine.  
But, with the UPROPERTY macro, i get this error:

“error : In MovementHelper: Member variable declaration: ‘movementFlags’ already defined M:\Documentos\Copy\Programacion\Proyectos\UE4\GameFactoryCPP\Source\GameFactoryCPP\Components\MovementHelper.h 73 1”

What i’m doing wrong? :S

See ya!

---

<div class="post-metadata">

**Author:** ![Zhi\_Kang\_Shao](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zhi\_Kang\_Shao](https://forums.unrealengine.com/u/Zhi_Kang_Shao)\
**Post date:** [May 16, 2015, 2:59pm UTC](https://forums.unrealengine.com/t/variable-already-defined-when-uproperty-is-used/30259/2 "2015-05-16T14:59:01Z")

</div>

Had this issue before when using a variable name almost equal to class name, in this case FMovementFlags and movementFlags. Try naming your variable something different like myMovementFlags.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0cd3b792](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0cd3b792](https://forums.unrealengine.com/u/anonymous_user_0cd3b792)\
**Post date:** [May 16, 2015, 4:08pm UTC](https://forums.unrealengine.com/t/variable-already-defined-when-uproperty-is-used/30259/3 "2015-05-16T16:08:02Z")

</div>

Waw, it works! 😮 .  
I added a simple underscore before the variable names and now compiles like a charm :D.

Thanks a lot, also for answering so quickly 🙂 .

See ya!
