Is my use of TActorIterator and TArray correct?
Hi all. I'm trying to loop through my game world to gather all characters and store them in my TArray for use within my CameraActor1 class. Right now this is my code inside my CameraActor1 class:
My questions are:
1) Am I using TActorIterator function and TArray correctly?
2) If I am then how do I access my characters within my TArray? I've tried arrayOfCharacters.GetActorLocation() so far to no avail. Any help is appreciated.
asked Apr 14 '16 at 07:49 PM in C++ Programming
You deceleration of character array seems to be invalid, TArray is dynamic array so it has no array size limit (well maybe addressing limit) TArray will reallocate the array in memory when needed, so this  at the end may mess up things. You can tell TArray to allocate array staicly by doing this:
Also you should place UPROPERTY() before TArray declertion, without that this array won't be tracked by garbage collection and when character will be destroyed you will have a nasty invalid pointer in that array (or else you manually remove it when actor is destroyed)
TActorIterator use looks ok to me. You see "Character Initial Location:" in logs right?
I assume you use "GameCharacter" name to mask real name if class, all actor should have A prefix in class name
Follow this question
Once you sign in you will be able to subscribe for any updates here