In blueprints I have a function that takes in the Pawn and target Actor, calls Move To Location Or Actor using that data, and then on finish I need to perform some actions on both the Pawn and Actor… but by that time I may have called it again for a new Pawn and target Actor, so those references aren’t stable.
I can’t store it in a map, as I don’t have any reliable references to the Pawn/Actor it was called for.
Can that Async pin be used in some way? I’ve tried finding out what info exactly that stores, and when it can be accessed, but I’m struggling to find that info.
This must be a long since solved problem, so I’m guessing I’m missing something simple.
I’ve tried using the Async Task as the key to a map to first store the data about the move operation, and then retrieve it on finish… the problem is the same. I guess the Async Task doesn’t change between calls to Move To Location Or Actor
it sounds tricky to manage multiple pawns at once in a actor.
I would avoid to take charge of their minds.
how about put the movement function in the pawns and do a for each loop to give the target to each pawn,call their movement function.let them to self-decide what to do next.
I’m not managing the Pawn’s in an actor, I’m managing them in the PlayerController. It would be messy design to have the Pawn’s giving themselves orders instead of the PlayerController.
And what would that mean for replication if that logic was in the Pawn?
For context, I need this code to run on the server specifically as I’m spawning the Pawn, then giving it move orders, then on finish I’m destroying the Pawn and spawning a new Actor… then a variable in another actor will be changed and RepNotified to all other players as the side effects of that change will vary depending on the player… The chain of events is already complicated enough without including the Pawn (or even it’s AIController) in the chain of logic.
It can’t be uncommon to manage multiple Pawn’s in one PlayerController can it? The PlayerController can’t only be designed for 1st/3rd person games with a single Pawn per player…
To be honest, the title, the post itself and your response suggest 3 completely different problems.
Are you storing the Pawns you’re managing in an array?
Are you planning on performing the actions within the function itself?
What do you mean by “those references aren’t stable”? The function has two inputs: Pawn and the Target Actor, correct? and these inputs will be valid as long as they have valid references when you call the function.
The solution could be as simple as creating an array of Pawns (or Targets), and inside the MoveTo function get a reference to this array and use the CONTAINS function to check if the input Pawn/Target already exists in it, if not, add it to the array and continue, then remove the Pawn/Target from the array once the Pawn is destroyed.
You mentioned that you need this code to run on the server specifically, using an AIController seems to be more appropriate than a PlayerContoller for this.
I don’t see how the title and post suggest different things. The post is just expanding on the title. Hopfeully you’re taking the title into account when reading the original post. My response was to the person who answered with a suggestion that I feel seems totally against reasonable design, as I made clear. If that seems off topic, either I misunderstood them or their suggestion was off topic I guess.
I have tested using the reference to pawn passed into the function that calls Move To Location Or Actor to first add a map element, and then use it as key when the Finsihed pin is executed… But as expected and already covered, if another call to that function is made for a different pawn, then the input pawn/etc. are overwritten with the new data, and so the state of the input data isn’t stable/predictable/correct nessacarily when the async Move To method finishes.
I have put the Move To part in the AIController now and it works ofcourse as they know which Pawn they control… but I don’t agree that’s a more sensible design. The AIController is now telling itself what to do. It makes much more sense (and is much cleaner) for the PlayerController to give instructions to AIControllers that are controlling that player’s pawns
That would mean the server would manage the NPC’s.
I’d put the Move to Location function in the Pawn class. So each pawn has it’s own move to. Call the function via an event. Pass whatever you need from the controller to the event.
On finished can call an event on the controller if need be.