Blueprints do not need to be mapped 1: 1 to C++.
For convenience, testing for equality is always look the same in BP, but that doesn’t mean it’s one and the same path. Under the hood, depending on the types compared, completely different functions can be used.
Again. The very idea of testing the equality of floating point variables should turn on a red light in your head.
Instead of writing WHAT you want to achieve, you chose one solution and focus on HOW to achieve it. Looks like XY problem.
We don’t know what an ItemGroup is, we don’t know why you are storing UsedLocations at all, whether the used location can be released and returned to available locations, etc. Are these available locations dynamic or static?
This is the basic information you need to solve the problem, not how to get around compile errors.
1, ItemGroup is a class of 5 static meshes and each static mesh is returning its static location in world transform
2, Available Locations are those vector transforms stored in the data table, will be used to generate unique spawn locations
3, UsedLocations is used to store any non-duplicated location which is ready to set to the static location of the available mesh location in the ItemGroup class
4, Location is used to store the valid actual location taken from UsedLocation after double checking for duplicates to set it to the world transform location of a static mesh, this will be actual spawn location for static mesh which will hold any item static mesh as a piclup mesh.
somehow I achieved it and the result can be seen in this image, each group has random items and each random item has assigned its random location in range on the bases of the locations provided in data table, there is no duplicate location, its mean every item has assigned its own unique location from the list of locations recorded in the data table
Lets analyze your GenerateItems() function.
At first, there is a loop for fetching locations from Data Tables and spawning AItemGroup actors.
At line 108 you call ItemGroupRef->GetAllTransforms(...). From where? This object is just spawned few lines before, so? You paste GetAllTransforms(...) definition in another thread and this function grab transform from meshes… but who set it? If AItemGroup just holds some meshes, why you ever set location for AItemGroup?
Line 32 & 34. FTransform have a proper constructor for this. Using Kismet function for this is bloat.
Line 39: Functions have return type for some reason. And C++ uses RVO/NRVO (return value optimization). Don’t avoid it, use it.
Line 39: I dont get it. You have fixed number of item types, but your loop have random number of iterations. And only unique item types are added. This is illogical. If the AItemGroup can have various number of item, then your other functions dont take it into account (like GetAllTransforms which always get transform from all five meshes).
Line 54: Unneccessary loop. You can do it in previous loop
line 74: Another unneccessary loop. You know which item is a E_Weapon when you randomize item type. You can assign ammo to weapon there
Line 88: Yyy… what? Completly dont understand. Besides that you modify container inside for-each loops, which is dangerously.
Line 103: This code have no effect, and can be cutted completly. Why? Because you dont store results anywhere. Everything are a local variables, destroyed after function returns.
Same situation is with RandomItemID(...) function. A lot of duplicated code, hard to read and maintain. Handling probability is really inefficient.
No offense, but this code is bad. I won’t be surprised if its performance is worse than the blueprint version. Because of this, you will only wander into more problems.
I manually sets this transform to make them not overlap each other, they are all connected to one scene component GetAllTransforms returns the world transforms of the 5 static meshes stored in the array
these 5 meshes are empty and they don’t have fixed items, the items are attached to them dynamically in another base class of Pickupitems, first the group actor spawned and then the item attached to each of the static meshes it holds empty.
this contains the function generate items function, if you have any question about any part or anything else i will explain , this code runs the first time and then when I close the game and re-run the engine freezed.
but when i comment do/while loop at line 101, the engine not freezed.
when i decrease the rows of locations in DT_ItemGroupSpawnLocationLobby the game works fine.
I could probably help, because this code can be improved or even some (or most) of it can be delegated to another thread.
I just don’t understand one thing. Namely, the loop on line 72.
Why if the type is E_Weapon then you add E_Ammo and remove something from the array?
At the same time, in your image from post 62 there is a case that AItemGroup has E_Weapon and notE_Ammo. I don’t know what the rule is to apply here.
Looping ItemIDArray to spawn items, if the item type weapon is selected to spawn so spawn the related ammo for that weapon and remove the first item in the array if the item is not a weapon to make space for ammo item to be spawned.
The array size is fixed according to the item count during looping.
if the first item is not removed in the array which is not a weapon, the loop will return array out of bound
Ok, but you don’t check anywhere if the item E_Ammo has not already been drawn.
If in a given iteration you draw three types: E_Health, E_Weapon and E_Ammo, then when this code hit E_Weapon - you add E_Ammo and remove E_Health. As a result, it becomes: E_Ammo, E_Weapon, E_Ammo.
This situation breaks the rule of uniqueness.
the first ammo item spawned is random, and the second is the specific type ammo for the weapon to be used with.
example: if ammo for shotgun is spawned random, and weapon ak47 spawned random but it need the ammo for ak47 so we remove the first item on any index if the item is not a weapon and spawn the ammo for ak47 in the same group
here the group of 5 items spawned and we can see ak47 has its own ammo in this group spawned, I don’t know what was removed from this group and replaced with ammo for ak 47, it can be another type of ammo or health or any other type which is not a weapon the loop will find first
Thank U for posting the code, I have analyzed it and found that you need two do/while loops at the same time to do this, since you want to set the locations in live process of spawning item and each time the location is changed for new spawned.
1: Check if the locations are duplicated or not / add not-duplicated to UsedLocations don’t set it.
2: Check if the UsedLocations has duplicates or not / set it to spawn locations only if they are not duplicated.