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"

Use Multiple points from Target Point Array

Time for my second noob question... I'm trying to make treasures spawn semi-randomly. By that I mean, I want to be able to set.. lets say 20 target points on the map, and then have my treasures use 10 of those. I want to be able to set how many spawn, but I want the spawn locations to be random. How can I do this? (Ignore the Widget and Viewport thing, that's used for the score keeping in the actual level)

Thanks in advance for anyone who attempts to help with this!

Update: I added some target points in. And thanks to Klawd3 I have been able to figure out how to make it spawn multiple treasures. However, now I need a bit of help figuring out how to make it so that when a target point is used, it won't use it a second time. (At the moment, I sometimes get 2 treasures that will spawn in the same spot, and I would prefer to have them spawn in their own spots). alt text

[1]: /storage/temp/90403-noob_question2.png

Product Version: UE 4.11
Tags:
noob_question2.png (315.3 kB)
noob_question3.png (402.4 kB)
more ▼

asked May 13 '16 at 01:08 AM in Blueprint Scripting

avatar image

Cougarkillz
22 5 7 8

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

1 answer: sort voted first

You want to spawn 2 objects ? You need a forloop going from 0 to 1 (two executions), and to avoid using the same spawn point twice, you can copy the array in a temporary variable, and remove the used location from the array at each execution.

more ▼

answered May 13 '16 at 06:27 AM

avatar image

ClaudioPiccinni
234 24 20 28

avatar image Cougarkillz May 13 '16 at 06:35 AM

Can you give a quick example of what that might look like? I'm looking up for loops on youtube now. But a visual of the blueprint would be amazing for trying to learn this.

avatar image Cougarkillz May 13 '16 at 07:01 AM

Especially the part about copying the array to a temporary variable and removing the one that was used.

avatar image Cougarkillz May 13 '16 at 07:11 AM

Okay... I got a working loop. The tutorial on youtube was actually quite helpful with that. Now I just need to figure out how to make it so it wont use the same target point more than once.

avatar image ClaudioPiccinni May 13 '16 at 08:10 AM

Just to give you an idea. Create the temp array as an empty duplicate of the original array containing the intended locations (vectors). alt text

screenshot_30.png (111.9 kB)
avatar image Cougarkillz May 13 '16 at 08:59 AM

I tried using that setup and it isn't working. I mean, it compiles, but it runs the same way as it did before. I have 10 target spawn locations, and to test if it works I make the loop run 10 times so 1 treasure should spawn on each location. However, when I play, it will sometimes have 2 or 3 or one time there was even 5 on a single spot, so I know it isn't spawning only 1 per spawn point. I'm going to attach my blueprint, can you tell me if I'm missing something? alt text

The thing attaching to the "set" box is just my even begin thing and the viewport boxes seen in my other screenshot above.

noob_question4.png (381.6 kB)
avatar image ClaudioPiccinni May 13 '16 at 09:50 AM

two things first:

fundamental rule: never use level blueprint unless you absolutely have to. second: you can store the transforms/vectors inside an array in the blueprint without using the persistent actor references like you did. Like this:
alt text

Probably the problem is that the forloop executes all in one tick (it's not a proper for loop), so it doesn't really care for the objects we are removing from the array. You could simulate a step-by-step loop with something like this:

alt text

you set the index default to 1. and the other variable to the number of actors you want to spawn, after the decrement int node remove the location as you did before

screenshot_31.png (84.1 kB)
screenshot_38.png (25.3 kB)
screenshot_38.png (25.3 kB)
avatar image Cougarkillz May 13 '16 at 10:22 AM

Wow I'm all confused now. What happens to all that stuff I just added in? I'm going to guess that the "true" part of the branch would plug into the "remove" box. I remove the "forloop" box and then... do I get rid of my temp array? Or do I plug the "set" box into the "spawn actor" box directly?

I know, I'm a pain to deal with because I'm so new at this. Please bear with me a little longer. =-b

avatar image ClaudioPiccinni May 13 '16 at 11:27 AM

It's ok, it takes time to figure things out.
Remove the forloop because, as I said, it executes all of its "loops" in one single action, so it doesn't really care if you remove the items from the temp array, because it uses it only once. Keep the get actor transform part and attach it to the new. And lastly, just after the spawn actor node, put the remove from index you did before. Yes the temp array is still needed.

PS: remember not to use Level Blueprint, just move everything to an actor blueprint. LB is really never needed, and it can cause different problems. When moving things away you'll need to figure out how to make the array how I showed you since you can't use the references to persistent level outside LB.
Bye. (and remember to mark the question as answered if we are done :))

avatar image Cougarkillz May 13 '16 at 11:42 AM

I think I screwed up.... it only spawns one item now. I turned it into a vector array (I'm still using the persistent actors, just getting the transform. I don't have their locations set in the world yet, once I do i'll set them instead of using targetpoint references, I'm using this to test to make this function work and then I'll polish it once the basis works). So, here is what is going on now... Any thoughts on where I screwed up? alt text

noob_question5.png (143.2 kB)
avatar image ClaudioPiccinni May 13 '16 at 12:31 PM

It only executes once because when the branch is false it doesn't go back into the spawn actor node, you forgot a piece :)

avatar image Cougarkillz May 13 '16 at 12:41 PM

I connected the branch false to the spawn actor node, and now it's back to doing what it did with the ForLoop.... it spawns 10 treasures but not 1 per spawn point. Some spawn points wont have any and some will have 2 or 3. Any other ideas?

avatar image ClaudioPiccinni May 13 '16 at 01:05 PM

sorry, missed something, you have to promote the Get node to variable. put it before the spawn node. then use a get on that variable for the remove node. It should work then

avatar image Cougarkillz May 13 '16 at 01:22 PM

I'm not sure what you meant by "node" so I right-clicked on the circle in the get box and made that a variable, and then got the variable to plug it in to the remove box. It still does the same thing. I've been up all night though watching tutorials and reading and trying your ideas, so I'm gonna pass out for a while. When I get up I'll transfer everything to an actor blueprint and use n actual transform array with locations. This is what it currently looks like though, if you see any glaring mistakes: (I drew a red line from the circle i promoted to variable, to the variable get part) alt text

noob_question6.png (185.2 kB)
avatar image ClaudioPiccinni May 13 '16 at 02:47 PM

Nope, undo what you just did.
Right click on the pin on the right in the Get node, and select "promote to variable". It will automatically create a new variable and pop a Set node for it. Plug that set node before the spawn actor (also move the return from the branch to this set node instead). Then from your blueprint variables (big panel on the left) drag the new variable that was just created by the "promote to variable" into the graph and select get, to get a get node (lol) for that variable. Plug this into the remove, and try again.

avatar image Cougarkillz May 13 '16 at 03:26 PM

You know what... it works. The only thing I had to change was make the "NumberToSpawn" variable 12 in order to spawn 10 treasures. Index is 1 so I'm not entirely sure what is going on there.... but once I made that variable 12 it worked flawlessly. I'm going to mark this as answered since it now works. If you have any feedback on the variable needing to be 12 in order to spawn 10 nodes I'd love to hear it, but for now, it technically works.

Thank you so much for sticking with me through this. I've actually learned quite a bit from all this, even if it was just using your ideas. This is my first UE4 project, and people like you make learning this stuff tolerable. =-b

Update: It isn't necessarily the number 12.... the "NumberToSpawn" variable needs to be set 2 higher than the amount I want to spawn. If I set that variable to 9, I get 7. If I set 5, then 3 spawn. Etc etc. But oh well, I'm not complaining since this actually works now. xD

avatar image ClaudioPiccinni May 13 '16 at 03:55 PM

Show the code please.
Btw, I suggest to never leave things like that if they work but you don't understand why. Reason is they could give you unexpected problems later on, possibly making a gigantic mess. Think it like this, if you create a building on bad foundations the higher you go the greater the damage will be when it falls.

avatar image Cougarkillz May 13 '16 at 04:11 PM

That's a good point. Here's the updated screenshot of what's going on:alt text

Like I said, I don't know why but the variable "NumberToSpawn" has to be 2 higher than the number I want to spawn. So to get 10 treasures, I set it to 12.

noob_question7.png (197.7 kB)
avatar image ClaudioPiccinni May 13 '16 at 04:41 PM

It should normally only be 1+ the value you set in the variable- That's because you increment it AFTER spawning (if you do the math it checks out).
The problem with your code, that requires +2, is that after the Set Bronze Spawn you should enter in the Set New Var. It's like picking the first random transform. Then you pass that transform to the spawn actor, then you remove it from the array, then you check if you reached the desired amount, and if not you go back to the Set New Var, that's equal to picking another random item from the remaining items in the array, etc.

avatar image Cougarkillz May 13 '16 at 04:50 PM

Oohhhhh I get it. I disconnected the Set Bronze_Spawn from the spawn actor node, and instead connected it to the "Set New_Var" node, and then left he "Set New_Var" node connected to the "spawn actor" node and now the "NumberToSpawn" just has to be 1 higher than the number I want. (Basically the only thing changed is the wire coming out of "set BronzeSpawn" now goes to "SetNewVar"

And then if I set index to zero, then my "NumberToSpawn" variable is accurate. So if I make it 8, I get 8 treasures now. I'm learning! It's a slow process, but I'm learning! You are amazing at this.

avatar image AJ_Graphix Nov 21 '16 at 08:41 PM

Thanks to Klawd3's advice and Cougarkillz's discoveries on this incredibly helpful thread, I was able to create a node setup for how to use multiple spawn points from an array only once.

I have shared the setup below, which also factors in a random amount to spawn, and a random rotation for the spawned objects.

Thank you again Klawd3 for taking the time to explain the technique! In this setup, I omitted the temp array, however, I tried it both ways and both ways appear to work.

(Click on link at bottom of post to view larger image.)

alt text

(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