Making a Array for Vector Locations for a object in C++

Hello! Currently, I’m trying to replace part of my player blueprints with C++ but I’m having trouble figuring out how to even set it up. For example, should I use a TArray or a UStruct, etc? Here’s a picture of my blueprints to show you what I’m trying to accomplish.

Firstly in my player.h file I tried setting up a USTRUCT

UFUNCTION()
void Block1();
UFUNCTION()
void Block2();
UFUNCTION()
void Block3();
UFUNCTION()
void Block4();

UFUNCTION()
void SetShieldLocation();

USTRUCT()
struct MyShieldQuadrants
{
	UPROPERTY(EditAnywhere)
		FVector BlockLocation1;

	UPROPERTY(EditAnywhere)
		FVector BlockLocation2;

	UPROPERTY(EditAnywhere)
		FVector BlockLocation3;

	UPROPERTY(EditAnywhere)
		FVector BlockLocation4;

	UPROPERTY()
		FVector ShieldLocation;  //current shield location

	void ShieldQuadrants()
	{
		ShieldLocation = (BlockLocation1, BlockLocation2, BlockLocation3, BlockLocation4);
	}

	//FVector Quadrants()
};

In my player.cpp I tried ( I already have block1-4 Bind Actions set up)

MyShieldQuadrants::ShieldLocation = TArray<FVector> array;
BlockLocation1 = FVector(60.0f, -25.0f, -10.0f);
BlockLocation2 = FVector(60.0f, 16.0f, -10.0f);
BlockLocation3 = FVector(60.0f, -25.0f, -80.0f);
BlockLocation4 = FVector(60.0f, 16.0f, -80.0f);

void ATerraBase::SetShieldLocation()
    {
FVector NewLocation, ShieldLocation[0]

    }

TArray I tried this for the player.h file

    TArray<FVector> RootShields;
         RootShields.Append(BlockLocation1, BlockLocation2, BlockLocation3, BlockLocation4);

I’ve been looking through posts on here and other documentation from Unreal which is how I came up with the code I did. However, what I’m doing does not seem correct and I keep getting thrown errors. How should I set up an array for this function between player.h and player.cpp files?

I also understand I can accomplish the same thing without an array for what is shown in the blueprints. However the same values are used for many different functions which is why I’m trying to set it up the same way as seen in the blueprints. Thanks for the help!

I didn’t realize you could set it up like that! But it makes sense, I appreciate your help, this will be a good foundation for what I’m aiming to do. Thanks! I shall be writing a shieldcomponent for sure. At least I think I know what you’re referring to. I’m pretty new to UE4 and have mainly touched blueprints and not really C++ until recently.

You have problem with your design. Wrong syntax also wrong assignments. You are assigning nulls to string. Lets not go far away from your design. Generally shields designed like up right left down, 1 thing you can do is :

USTRUCT()
 struct MyShieldQuadrants
 {
    UPROPERTY(EditAnywhere)
    const FVector UPPER_BLOCK_LOCATION = FVector(60.0f, -25.0f, -10.0f); ;

    UPROPERTY(EditAnywhere)
    const FVector LEFT_BLOCK_LOCATION = FVector(60.0f, 16.0f, -10.0f);;

    UPROPERTY(EditAnywhere)
    const FVector RIGHT_BLOCK_LOCATION = FVector(60.0f, 16.0f, -80.0f);;

    UPROPERTY(EditAnywhere)
    const FVector DOWN_BLOCK_LOCATION = FVector(60.0f, -25.0f, -80.0f);;
 
     UPROPERTY()
         FVector CurrentShieldLocation;  //current shield location
 
     void ShieldQuadrants()
     {
         CurrentShieldLocation = DOWN_BLOCK_LOCATION;
     }

     void ChangeShieldLocation(int value)
     {
         switch (value)
         {
              case 0:
                    CurrentShieldLocation = UPPER_BLOCK_LOCATION;
                    break;
              case 1:
                    CurrentShieldLocation = LEFT_BLOCK_LOCATION;
                    break;
              // so on and so on.
         }
     }
 };

I would definetely write a OffHandComponent to manage those. Just have a look. I hope above code will get you somewhere.

I have converted it to answer. You can mark to help people find out solution. Feel free to ask other questions.

If you want to be extra fancy and make the system a bit more sophisticated, you can use an Enum and a TMap to hold these variables.

UENUM()
enum EBlockLocation {
	Up, Down, Left, Right
};

You could then give the Actor in Question a TMap Property and initialize the map in the constructor:

YourActor.h:
    TMap<EBlockLocation, FVector> BlockDirections;

Constructor:
    BlockDirections.Append(Up, FVector(...));

And then just Access the stored values with the [ ]-operator

Thanks for adding on!!! The “Actor” I’m using is a static mesh attached to a player character blueprints. Would I have to make a separate class for this to work?

Sounds great, thanks!

The only thing you really need to create is the Enum, which you can just add in your Actor.h file (Just paste it above your class).

And then I would just create the Map as a UPROPERTY on the Actor and add a UFUNCTION called “ChangeShieldLocation” or smt like this, that takes an “EBlockLocation” as Parameter.

Awesome, thanks for the clarification!