x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.17
Tags:
more ▼

asked Oct 06 '17 at 07:25 AM in Blueprint Scripting

avatar image

Ason
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

What you're looking for is called an array. It's a group of variables bound together.

Create a new variable array like this: alt text

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: alt text 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.

variablearray.png (22.0 kB)
arrayaccess.png (82.0 kB)
more ▼

answered Oct 07 '17 at 01:48 AM

avatar image

Ecnassianer
151 4 10 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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].

more ▼

answered Oct 07 '17 at 02:20 PM

avatar image

Ason
1 1 2

avatar image Ecnassianer Oct 07 '17 at 03:40 PM

To get a variable out of that array item, simply drag away 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 of the blueprint that you're accessing, you may need to cast it to the correct type to get that variable, or change the array type to the actual blueprint you want to keep track of.

There's a Remove option for arrays as well, when you're ready to get rid of an entry. It works the same as Add.

I've edited this into my answer for the question as well. If that helps you, could you accept it as the correct answer? :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question