Get AI character location C++
Hi, Note I am relatively low skilled in C++. I am trying to:
As far as I know, TArray and TActorIterator should do the job, but I can't seem to be able to use them properly. I was able to produce csv files. So the main issue is with the first two points. A detailed answer would be very much appreciated. Thanks in advance.
(comments are locked)
|
This would be one way to achieve what you want:
but it would be the most 'hacky' way, as the use of GetAllActorsOfClass() is even mentioned in its comment that is very expensive and mustn't be used every frame (what my example does), but if you trigger this method at a specific point in your game (e.g. when every ai character was spawned) then you can cache the resulting array from it and iterate through the cached array. If it is not deterministic for you to say when "every" AICharacter is spawned then I would recommend to add the AICharacters to a cached array, at the moment when they're spawned and removed when they're destroyed (but the information still would need to be persisted). But if you're a beginner then this might be a much more complex approach and not even needed. I hope my answers helped. Assuming all characters are spawned at time = 0 and no new characters get spawned or destroyed during the game. It should probably be not too hacky if we get references to the AI characters and save them in an array in begin play. Then use this array of references to call the location of each character AI in every tick. Any idea how I can accomplish that in terms of code? In this thread, the guy is trying to do something very similar to what I want to do but I can't get his code to work and he didn't really mention how he ended up making it work. Eh. Maybe I don't quite understand you, but the code I posted pretty much does exactly that. It gets alle available characters in the current scene and stores them into the TArray AICharacters and for easierer mapping with their Location into the TMap. Just place it somewhere else (not AnyClass.h
AnyClass.cpp
(comments are locked)
|
Follow this question
Once you sign in you will be able to subscribe for any updates here