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"

Make Mesh Always On Ground? (Procedural Generation)

What do I need to add to the construction script to make sure the meshes are always touching the ground? I'm trying to do EXACTLY what a procedural foliage spawner does, but using a blueprint actor rather than a foliage type.

Any other advice on how to recreate foliage spawner in a blueprint would be greatly appreciated! Thank you!

I'm using UE 4.18

alt text

Product Version: UE 4.18
more ▼

asked Jan 30 '18 at 06:08 AM in Blueprint Scripting

avatar image

19 4 7 16

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

2 answers: sort voted first

First you have to randomly generate a location above the ground, like you are doing already. Then, from that location, use LineTraceByChannel to fire a ray downward (negative Z direction) to the terrain. Get the Hit Results from the line trace and extract the Location (or Impact Point). That is the location on the ground where you need to finally spawn your foliage mesh.

more ▼

answered Jan 30 '18 at 07:50 AM

avatar image

2.2k 10 6 12

avatar image four2nothin Jan 30 '18 at 05:16 PM

Sorry to be difficult but what goes in to the execution pin for the line trace? And from hit actor, do I cast to landscape? Finally, as far as a negative 'Z' value for the line trace, can it be any value so long as it is negative?

avatar image vr_marco Jan 30 '18 at 05:27 PM

After the line trace you can indeed use a Branch to check that the ray hit something, then verify that that something is the landscape. You can avoid that by selecting Landscape as trace channel in the Line Trace by Channel node. You will still need to check that the ray hit something (Return Value should be true).

If you are use the Landscape trace channel there should be no need to verify the ray hit the landscape. This will always be the case.

Your negative Z should be long enough to reach the landscape. Not sure what an appropriate value would be in your case, it depends very much on the spawning logic. Start with something like 5000 (50 meters above) and increase it gradually if you have many missing hits.

avatar image four2nothin Jan 30 '18 at 06:18 PM

You'll have to pardon my ignorance, as I'm still learning.. I'm just confused as to what to hook up to the execution pin on the line trace. Is this correct so far?alt text

spawn-b-p.png (415.1 kB)
avatar image vr_marco Jan 30 '18 at 07:04 PM

Yes, look good so far. The IN execution pin of the Line Trace should come from some sort of event, a mouse click or a key pressed. The OUT pin should go to a Branch checking Return Value and, if true, should go to your foliage spawning.

avatar image four2nothin Jan 30 '18 at 08:42 PM

Hm, no matter what I do, there are trees floating above or sinking below ground.I have a very hilly/mountainous landscape So maybe I'm just not getting the numbers correct. Also, I'm setting this up in the construct, and I'm not able to find any mouse click events other than "bind to on clicked"

avatar image Alex O ♦♦ STAFF Jan 31 '18 at 11:32 PM

In this case I think the execution input will be the construction event. (so when the BP is created that executes and places the mesh on the ground)

avatar image vr_marco Feb 01 '18 at 05:13 PM

Sorry, I was offline during the past two days. Indeed, thanks Alex!

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

It might be too simple but, can't you use an static navmesh and use to get random locations to spawn?

more ▼

answered Feb 01 '18 at 04:14 PM

avatar image

524 1 4 8

(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