doing this in blueprint works that way and this is what I want
i am doing it on the right way if compare to blueprint version?
void AItemGroup::GetAllTransforms(/*Out*/ TArray<FTransform>& Transform)
{
Transform.Empty();
for (auto Mesh : { StaticMesh01, StaticMesh02, StaticMesh03, StaticMesh04, StaticMesh05 })
{
if (IsValid(Mesh))
{
Transform.Add(Mesh->GetComponentTransform());
}
}
}
That looks correct.
I think you’re over complicating this function, try this simple approch
TArray<FTransform> Available;
ItemGroupRef->GetAllTransforms(Available);
FCustomThunkTemplates::Array_Shuffle(Available);
for(int32 i = 0; i < ItemsIDArr.Num(); i++)
{
const FTransform& SpawnLocation = Available[i];
//ItemsIDArr[i].Type
//ItemsIDArr[i].ID
//Spawn here
}
now the locations are fine but and the actorgroup not spawned on these locations
Items did not spawned
That’s a good start, can you show how your function looks now ?
but I found the locations are not correct, they are floating in the air
You’re not using the type and ID as I suggested by that comment.
Replace this with
ItemsIDArr[i].Type
ItemsIDArr[i].ID
with
SpawnType = ItemsIDArr[i].Type
SpawnID = ItemsIDArr[i].ID
I fixed it and tried, some items are spawned correctly some are empty actor group floating in air
I think we fixed the location issue. What controls how the group looks like ? It’s probably something in those settings like SN
no the location issue is not fixed , there are empty locations spawning hiding under ground , when I click the spawn actor it takes me that unknown place and I see an empty actorgroup
I think we need to try to overload operator== for ftransform, and use the simple blueprint ukismet library Array_Find
function , which is used in the native code when I generated from this class
In this post these are valid locations.
I think something simple with the spawn logic needs fixing and you should be good, this is a better solution you can try it in blueprint.
I am sure it returning duplicates becasuse internally it is failing when compare if the location is already used and returning unknown locations
I found from the native code that the location is subtracted by -1 and then rechecked if the subtraction was successful before assigning it to any item to spawn
In terms of spawning the code is still the same, so it should work as before.
This is the only thing I don’t know what it does
MyGameInstanceRef->GenerateSN(SN_Wep);
NewWeaponItem->SN = SN_Wep;
How do you determine SN_Wep ?
void AMyGameInstance::GenerateSN(FString& SN)
{
SN = FString::SanitizeFloat(FMath::FRand()) + FString::SanitizeFloat(FMath::FRand());
}
I don’t what it could be, everything seems good for me.
One thing you can try to confirm the locations just after setting the SpawnLocation, log it and let me know if it looks weird.
const FTransform& SpawnLocation = Available[i];`
UE_LOG(LogTemp, Warning, TEXT("Location used: %s"), *SpawnLocation.GetTranslation().ToString());
If it looks correct then something wrong with the spawning.
FTransform SpawnLocaton{};
TArray<FTransform> Available{};
AItemGroup* ItemGroupRef{};
int32 AddArray{};
TArray<FTransform> AllTransforms{};
FTransform Location{};
int32 FindIndex{};
bool bEqualValid{};
int32 __CurrentState = 4;
do
{
switch( __CurrentState )
{
case 1:
{
if(::IsValid(ItemGroupRef))
{
(AllTransforms).Reset();
ItemGroupRef->AItemGroup::GetAllTransforms(/*out*/ AllTransforms);
}
AMyGameMode::RandomLocation(AllTransforms, /*out*/ Location);
}
case 2:
{
FindIndex = FCustomThunkTemplates::Array_Find(Available, Location);
bEqualValid = UKismetMathLibrary::EqualEqual_IntInt(FindIndex, -1);
if (!bEqualValid)
{
__CurrentState = -1;
break;
}
}
case 3:
{
SpawnLocaton = Location;
}
case 4:
{
AddArray = FCustomThunkTemplates::Array_Add(Available, SpawnLocaton);
__CurrentState = -1;
break;
}
default:
break;
}
} while( __CurrentState != -1 );
}