I was working with a TArray of pointers and I had some trouble. The TArray is of size 1000 and my goal is to copy the first 500 to the second 500. Originally I did it like this
for (int i = 500; i < 1000; i += 1) {
CreatureList[i] = CreatureList[i - 500];
CreatureList[i]->Mutate();
}
Here CreatureList is a TArray, but since an element of CreatureList is a pointer, its passing that pointer and when the function Mutate is called, both the creature at index i and index i - 500 reflect the changes of the Mutate function.
Note: The elements of CreatureList must be pointers because I need them to be polymorphic and from what I understand polymorphism only works with pointers in c++ (Correct me if I’m wrong about that)
I discovered a solution outside of unreal engine which worked perfectly fine.
for (int i = 500; i < 1000; i += 1) {
*CreatureList[i] = *CreatureList[i - 500];
CreatureList[i]->Mutate();
}
But when I use this syntax in unreal engine I get an error saying “UCreature &UCreature::operator=(const UCreature &) declared at line 27 of Creature.h is inaccessible”
In my header file, line 27 is
GENERATED_BODY()
Does anybody have any insight into why I’m not allowed to use this operator here? If there are any alternatives or workarounds, that would be great as well. I’m making an evolution simulator, and if every creature is mutating instead of a specific one in the population, then that would cause problems. Thanks!