Best way to get terrain positions from a given height range

Hi, I’m attempting to make a procedural system that will add features to a terrain based on height at runtime e.g. ports near water (height between say 15,20), castles on mountains (200+) etc,

I’m not completely sure how to go about it. My current idea is to get the height map from the terrain, run through every pixel and test it against the values and if it is in the range add a vector representing it in world space to a list.

Then randomly select values from this list to add an object if there is room.

This feels like a very brute force way of doing it even thought its unlikely to happen very often in game (doubt it will happen more then once every few minutes since it will only run when a new terrain “Tile” is generated) i was wondering if there are any better solutions / some sort of plane-terrain intersection method that could be used to make the process run smoother.

Any ideas would be appreciated.

Why don’t you launch a Raycast on -Vector3.up from an object wich is located above the scenario and check the position of the hit point? This way you can check the Y position of the hit point and calcule when add a certain map asset. If you need some help at scripting of this just let me now. (:

I know this post is from 3 years ago but in case you, or anyone else, is interested in a good answer, you can’t just say “give me all the points that are within my port range or my castle range”. If you have a function give you all the heights in your “castle” range, for example, they’re going to be all over the place; you probably won’t get what your looking for–an area large enough to lay down a castle, for example.
My best suggestion is Paint Height tool for Terrain (second tool button from the left for your terrain object). Then, hold shift to sample a terrain height at your chosen destination and then you’re going to have to “paint” the height of the area around it to flatten it enough (at that height) so you can place a castle, etc. The kinds of natural looking “fractal” terrains we all use are much too bumpy to just place such a large object within one of your height ranges unless you manually edit it.