crest
crest copied to clipboard
When sampling height using SampleHelpers or directly, the first request always fails
Describe the bug We discovered this issue while trying to make an editor function to sample the water height. But it also affects play mode.
We start with your OceanSampleHeightDemo, which places a cube at the surface of the water. Out of the box this works fine. But if we try to run the Query just once, it always fails.
I put the function on a button instead and noticed that it would always work (either at edit or play time) if I double-clicked the button, and would never work if I clicked once (no error is thrown, it just fails to get a result)
We found line 121 of QueryBase.cs - it has an 'if age < 10' basically here's what seems to be happening:
- if I query twice or more and the queries are <10 frames apart, then it works and the results are returned almost instantly
- if I query 1 time only, it never works even if we wait forever for the results to be filled
- if I query more once, more than 10 frames apart, it doesn't work
We confirmed this behavior by increasing the age limit. It's not visible in normal gameplay where a query is being made at 30 or 60fps, but single queries will always fail.
I understand GPU queries are by nature async methods and we are happy to write async functions to handle the results. But even so, the first query should return results. We want to use it for our editor methods but also for one-time visual effects in gameplay, such as placing splash effects when an object first hits the water.
Log Nothing in log
Versions Built in renderer, latest Crest 2 May 2022, Unity 2021.3.0f1
To Reproduce Open your sample scene. Create a cube and add OceanSampleHeightDemo. Modify the function to query water height just one time. You will see it never works.
Platform
- Editor
- Windows
Hardware Geforce 2080 Super
Hello, the current system requires that one calls the query function each frame until it returns true and provides data. In other words it requires "polling" for the 2-3 frames until the result comes back.
I think we have an idea of how to make it behave more like what you are expecting but it would involve a major overhaul or replacement of the current system and I don't have a timeline on that currently. Can reply here again if that changes though.
That's fine, but I'd appreciate any advice you can give on the best way to work around this for an editor script. We can write an async method if required - performance is not an issue since this only will happen at build time. Should we just issue the request over and over again until it returns data? Will that work?
It's hard to say for sure but I suppose if you jump on the same tick that the OceanRenderer is using to drive its update (it also needs to update in edit mode/editor and so has its update code called from multiple places) it might all just work.
Generally it should also be safe to spam it at high frequency, I believe. Needs to be tried though.
Ok thanks we'll give it a try.