Blueprint variable

Hi ive created a variable i need each new blueprint instance (of the same type) to have a different number. obviosuly i just need to increment it but im not sure where/how i should increment the variable, should it be down when i create a new instance of the blue print?

whats your aim here. are you just trying to set the variable to a different number for each actor you place in your level? or is it something you want dynamically done while playing?

if you just want to set the variable to a different value for individual instances of the actor in the scene then just make the variable public by clicking the little eye icon next to it. this will enable you to change the value of the variable in the details panel in the level view window.

if you want the value to change while playing then we need to know your aim to create a script that works.

when i spawned multiple pawns they all used the same player controller so ive tried to set a variable and increment it each time so it would correspond to each player controller, ie player 0 player 1 etc.

I feel like this is probably not how you do it but i did something similiar for getting the correct hud to display for each pawn so i thought it would work the same

so your just trying to have a integer that matches the controller number. have you tried using the “get player controller id” node? thats probably your best bet.

ive thought of a few different methods that may work but i dont believe that they will work correctly every time which means their out. issues arise if players can come and go and i dont know enough about the assignment of controllers to get too detailed. the get controller id should work everytime though so thats what i would go with.

  1. In pawn BP create an integer variable like “Controller Index” and set it to “instance editable” AND “expose on spawn”
  2. On begin play, “set controller ID” or whatever that node is that sets the controller index to the “Controller Index” variable we created
  3. In the BP that “spawns” the pawn have a comparable integer variable,and use that as the input into the “Controller Index” variable that will be present on the “Spawn Actor From Class” node.
  4. After each “spawned” pawn increment the variable
  5. This will work fine as long as players don’t have the ability to come and go, otherwise you can end up with controller #15 for a game that only supports 8 players, not sure how that would all work out