Download

accessing array of player controllers help

Hi all,
Im trying to access an array of player controllers so that I may take each one and set a new view target of a camera I have attached to the main character. First I have the default pawn as default pawn in game mode and on my server controller it unposses its pawn and possesses the character I have dropped into the editor. I have 2 extra cameras attached to the character that I am attempting to set as the new view targets for clients in multiplayer. I have tried a few different ways to access the array and pass the elements to the set view target with blend but coming out of the foreach loop it basically is taking ALL controllers and running them through the camera blends instead of each one doing a seperate blend. I cant seem to figure out a way to access each element individually so that I can set the view targets as I would like. Id love some help as Im definetly lacking in c++ skill.

So what exactly is the behavior you want? You want each controller to have a different camera?

Your ForEachLoop doesn’t make sense by the way. You are casting the same Array Element 3 times in each loop. Do you understand how a ForEachLoop works? The idea is that every time Loop Body executes, you receive the next ArrayElement. So you should only have to cast it to a player controller once. Now, if you’re wanting to do a different camera for each player, you should maybe have a Switch after the cast to player controller (the one and only, not 3) that switches on player index and that decides which camera to take. Then again, I’m not really sure what your goal is, but your sequence of casts is unnecessary (and likely indicating you didn’t really understand how the loop works).

Thanks for the help,
Now I do know how a foreach loop works, what was posted was just my last attempt before I got frustrated and decided to ask for help. I know that it goes through the array of elements and each one can have a seperate “do this” once its called. Its more figuring out which blueprint node to use to achieve the desired result. I have 3 cameras in my scene…foreach playercontroller…PC 1 → take camera 1 view, PC 2 → take camera 2 view, etc. My problem is the execution of nodes to take each element of the array and do something with it. I just havent found the right sequence of nodes since Im a newbie to this blueprint stuff. Thanks for your help. And yes looking at that pic it clearly shows all elements going into that sequence node so that definetly wouldnt do the trick. As I said i was getting frustrated :slight_smile: Later tonight I will try the switch and let you know what happened.

I figured out the issue and set view target with blend was not the way to go. In the end I was able to get desired results by casting player controllers and having them possess the camera pawns I wanted. This thread can be closed.