Get Terrain Height At Any Given Location With Data From Other Blueprint

Hi There, so my project makes good progress but now I’m a little stuck.

I’ve generated a terrain within the construction script of blueprint “createMap” with only one Hierarchical Instanced Static Mesh called “Terrain6565”:

Now within a new blueprint “createTree” I want to generate trees in the very same way as I did with the tiles, however I need to know the height of the terrain for each x-y-position where a tree is due to be placed. I though about doing it with a Line Trace Component and use “Terrain6565” as target and I think this should return me the z-position of the terrain at any given x-y-point, however…

Well how do I get data of my Hierarchical Instanced Static Mesh called “Terrain6565” from within blueprint “createMap” into the new blueprint “createTree”, any ideas because I couldn’t find a clear answer myself so far?

Thanks for any Help!

You spawn “createTree” as often as you want in the construction script of “createMap” and make variables “Editable” and “Expose on Spawn”.
Now you can set variables when calling “Spawn Actor” and use those variables in the construction script.

Thanks for your suggestion, however I do not quite understand how I actually “do” what you say… could you give me an example with nodes or so?

Here you can take a look at the “createTree” blueprint, hope it helps:

the “createTerain” blueprint looks more or less exactly the same except with a terrain mesh and different transforms… now all I need are the proper z-positions of “Terrain6565”, so that the trees are actually on the surface and not above or below it…

Thanks for your effort!

Sure.

Looks like you cant spawn actor from the construction script… so you need a function aswell.
You can do this with arrays aswell or what ever you want (you could even give the reference of createMap and get every variable from it).
Linetraces sound like the best way to get the positions you want.

Thanks but I still can’t find a solution to my problem…

EDIT: Well I’ve looked over it again and the real problem is that the SpawnActor doesn’t spawn anything, the only way I’ve found possible to make the spawnTree blueprint is by making it a ChildActor and the use SetChildActor Class but like that I cannot change any of the variables anymore…

Maybe someone can make sense of that and help me, I would be so thankful for any advice!

Ok my bad.

You could also just do the linetraces as you said, you only need max/min Z of your terrain defaults and then wont need any communication between those blueprints.
Or make it one blueprint instead of two?

lineTrace > break hit > get hit actor > castTo: CreateMap > [on success] CreateTree at location of hit.

Well I do want to have blueprint communication, trees are not the only thing that will come onto my terrain. It would be sloppy (and as I heard not very wise) to just pack everything into one class and make it excessively big. There will be all sorts of other things I would need to include: stones, shrubs, buildings, npc’s and so on… for all of these I want to make individual classes otherwise the blueprint would get very confusing.

Thanks for this, I sort of knew I would have to do some casting (even though an example with nodes would have been more insightful since I already tried something similar and it didn’t work). I will still try out what you say, thanks again!

Well thanks for the effort anyway… as soon as I have the result I was looking for I’ll post my solution,
Have a nice day!

UPDATE - PROBLEM SOLVED!

Hi there, so after some time I realized that I cannot do both the terrain creation and the tree creation within two separate Construction Scripts. I’ve moved all nodes in “spawnTree” from the Construction Script to the Event Graph and now it works perfectly fine:

You can see here that I’ve used LineTraseByChannel to find the terrain collision point, that’s where the tree will have its z-position. I’ve also randomized the x and y position a little so that the trees are not perfectly aligned. The result is very rewarding:

So, thanks again for anyone who has helped me. Even though the suggestions made didn’t solve the problem for me, they surely gave me some more insight and therefore ideas on how to find a solution and for that I am grateful!

Thanks for your Contribution!