How to store local variables?
I'm making a turn based battle system and now I try to implement a creature queue, which should determine the order of activation of the creatures. I created a simple raw C++ struct which looks something like this:
The question is how should I store the records inside a member TArray variable? Should the struct be a USTRUCT and ACreature* a UPROPERTY?
A FQueueRecord instance is created loaclly inside a method. After adding a new record, the queue is sorted based on the PointsToNextTurn variable. Would the use of a smart pointer be a good option? If so, which type should be used: std::unique_ptr, TUniquePtr or even TUniqueObj? Or is there any better solution?
(I considered a TMap for this, but it should be possible to add the creature more than once.)
asked Sep 11 '18 at 08:23 AM in C++ Programming
Yes if you using UObjects you need USTRUCT and UPROPERTY in it and TArray need to be UPROPERTY too, so engine see those varbales and can automatically null invalid pointers of destroyed actors (ofcorse oyu will need to do struct cleaning in your case). Other then that it's needed to other thing, it's not dangerous with actors but if you got pure UObject you need to have them referenced in the way engine see them or else they be trashed.
I don't know what you mean by local varbales as the way you describe sound not like local variables (mean varbales in scope of function). If you indeed use local variable the all those doesn't matter as in scope of function engine won't able to delete those objects, even if you do that with destroy function they be just marked as pending kill and deleted after current frame, so in this case this is all optional.
All you need to know is that without all those U macros engine don't see those variables, and most impotently GC don't see it.
answered Sep 12 '18 at 03:13 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here