Hi all,
I’m trying to create a class that can randomly spawn a Blueprint class from a pool defined through a TArray in the editor. For this I have two classes: A Section class and a SectionScene class. In the Section class, you are able to add several SectionScene classes to an array in the editor. I have achieved this in the .h using:
//Create a pool of Section Scenes to choose randomly from
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Section Scenes")
TArray<TSubclassOf<class ATBSectionScene>> ArrSectionScenePool;
//The Section scene to use
TSubclassOf<class ATBSectionScene> SectionScene;
Then in the .cpp constructor I am trying to assign a randomly chosen Section Scene from the ArrSectionScenePool array to the SectionScene variable:
//If there are some section scenes defined in the section scene pool
if (ArrSectionScenePool.Num)
{
//choose a random scene from the pool and assign it as *the* scene
int sceneIndex = (int)FMath::Floor(FMath::RandRange(0, ArrSectionScenePool.Num));
SectionScene = ArrSectionScenePool[sceneIndex];
}
I now get the following error:
…TBSection.cpp(14): error C3867: ‘TArray,FDefaultAllocator>::Num’: non-standard syntax; use ‘&’ to create a pointer to member
I come from a Unity/C# background and honestly don’t really have any idea what this means. I tried converting the TArray into a pointer but apparently this is not allowed in UE4.
Am I doing this completely wrong? Is there a best practice way to achieve this?
Thanks in advance :).