Hello,
I’m trying to implement a simple feature where I want to change the material of an OSM building when it’s clicked/hit. I want to achieve this without relying on OSM metadata, simply changing the material of the specific building that was hit.
What I want to achieve:
- When a user clicks on an OSM building, only that specific building’s material should change
- The material change should be temporary (for highlighting the selected building)
- Other buildings should remain unchanged
- This should work independently of OSM metadata
Questions:
- What’s the most effective way to change material for only the single hit building while ensuring other buildings remain unchanged?
- What’s the best practice for handling this material change without relying on OSM metadata?
Environment:
- Unreal Engine Version:5.3
- Cesium for Unreal Version: 2.8.0
Any help or examples would be greatly appreciated. Thank you!
Hi @spaid_ue,
Well, what you’ve described isn’t really possible. The problem is that OSM buildings are batched together. A single “draw” draws many buildings. So you can’t directly render one building with one material, and the rest with another.
Instead, you have to… use the metadata system! That doesn’t mean you necessarily have to use individual metadata properties of the buildings, but the metadata system is what will allow you to distinguish the triangles that make up one building from the triangles that make up another.
Before I go into any more detail about how this would be done, let me check in: is this approach acceptable? Why are you specifically trying to avoid metadata?
Thank you for your detailed explanation. I have no specific reason to avoid using metadata - I was simply looking for the easiest approach to implement this feature. Since metadata seems to be the proper way to achieve this, I’d be very interested in learning more about how to implement it. Could you please guide me through the metadata approach?
We just released a new version of the Cesium for Unreal Samples project that demonstrates how this can be done. You can get the latest version here:
Then take a look at Level 14 - Architectural Design. It has a custom Blueprint and Material that work together to highlight the clicked object.