How to Break Struct? C++

Hi, I want to break struct to set its properties, I hope you have experience with that and can help me.
Blueprint version.

I am stuck here.

for (int32 i = 1; i <= WeaponItemDatas.ProbabalityPercent; i++)
	{
		Arr.Add(/*Here I am stuck, how to break struct and set its properties*/);
	}

There’s no “break struct” for C++, that’s a BP convention. You simply need to create an instance of your struct and populate the values…something like this

FST_ItemTypeAndID TmpItem;

for (int32 i = 1; i <= WeaponItemDatas.ProbabalityPercent; i++)
{
	TmpItem.Type = blah;
	TmpItem.ID = blah;

	Arr.Add(TmpItem);
}

Of course I don’t know if you’re using proper naming conventions but your struct should have an ‘F’ at the beginning like I have it in the example above…and of course replace the blah’s with actual values :slight_smile:

2 Likes

Thank you sir very very much for this perfect and easy solution , I really appreciate :slight_smile:

I followed your answer and it works fine for now and compiles.

for (int32 i = 1; i <= WeaponItemDatas.ProbabalityPercent; i++)
	{
		TempItemTypeAndID_var.ID = Array;
		TempItemTypeAndID_var.Type = EItemType::E_Weapon;
		Arr.Add(TempItemTypeAndID_var);
	}

I would like to confirm that I am setting the Type correctly grabbing from enum ?

TempItemTypeAndID_var.Type = EItemType::E_Weapon;

This page can help:
https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/DevelopmentSetup/CodingStandard/

It will be better if instead of naming Type you name it as WeaponType, something more specific.

1 Like

yes in case if I have one type of item but I have them many and the variable TempItemTypeAndID_var is used to set ID and Type for each of them.
testtransform37

Yes, that is indeed the correct way to assign an enum

1 Like

All Ok :slight_smile: