Storing blueprints instances for specific player.
Hello, I'm currently trying to make a very simple RPG game. I have made a blueprint with a box mesh and a collisionbox, what I would like is that when a player steps into the triggerbox, the box should be added to a list that contains all the instances of the box blueprint that the specific player has "collected".
For example there are 5 instances of the box around the map, player 1 step into(collects) two of them, player 2 steps into(collects) three of them, now I want to know which boxes belongs to each player.
Also if possible, I would like to know how to access the variables in each box, so each box has a variable that determines how much gold it contains(random integer), so I want to know the total amount of gold that each player will get.
Anyone know a good way of doing this?
asked Oct 06 '17 at 07:25 AM in Blueprint Scripting
What you're looking for is called an array. It's a group of variables bound together.
Create a new variable array like this:
Make sure you turn the little pill icon next to Variable Type into the grid. This means it's an array of variables, instead of a single variable.
Now you can put things into your array and read them out: The green pin is an "index" it just means the slot number of whatever you put in. You can save it for later, or you can use functions like "Find" or a For loop to search for whatever you're looking for in the array.
To get a variable out of that array item, simply drag way from the pin and type the variable name in the box. Context Sensitive search should bring you right to it. In my case I used Actor blueprints, so I grabbed the Can be Damaged variable. If your array type is a parent class blueprint that you're accessing, you may need to cast it to the correct type to get that variable.
If you need to know more about arrays, try googling "unreal blueprint arrays", you'll find lots of documentation.
Yes this is what I need, but how do I go about getting the variables from the actors that are put into the array?
For example: 2 actors are placed in the array, each of the actors have a [goldAmount] variable that sets a random integer between 1-5, I now want to add these togheter for a [TotalGold] variable, and I also want to be able to remove an actor from the array if X happens, togheter with it's [goldAmount] variable from the [Totalgold].
answered Oct 07 '17 at 02:20 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here