Dynamic Water Physics 2 [Released]

For anyone out there still using Ultimate Water System. I threw together a DataProvider for that library.

You’ll also need to add the following to WaterObjectManager.cs line 423

#elif DWP_UWS
            waterDataProvider = new UWSWaterDataProvider();
            Debug.Log("DWP2: Using Ultimate Water System");

Then use the DWP_UWS in Project Settings → Player → Scripting Define Symbols

This uses the WaterSample class that runs the height queries in a separate thread, so it’s very fast.

5329512–536898–UWSWaterDataProvider.cs (4.75 KB)

3 Likes

I’m another victim.

1 Like

Unsafe part will be removed in the next update since Unity updated their API to include a function for copying from NativeArray to Array and vice versa.

1 Like

@NWHCoding I’m in the process of migrating to Crest and I’m having an issue.

Pretty much everything that floats in my game is a network spawned prefab, so I have to call Synchronize() manually whenever anything spawns.

This seems to break the Crest integration as I get tons of errors and everything falls through the water. Here’s the call stacks.

IndexOutOfRangeException: Index was outside the bounds of the array.
Crest.QueryBase.UpdateQueryPoints (System.Int32 i_ownerHash, Crest.SamplingData i_samplingData, UnityEngine.Vector3[] queryPoints, UnityEngine.Vector3[] queryNormals) (at Assets/Crest/Crest/Scripts/Collision/QueryBase.cs:245)
Crest.QueryDisplacements.Query (System.Int32 i_ownerHash, Crest.SamplingData i_samplingData, UnityEngine.Vector3[] i_queryPoints, System.Single[] o_resultHeights, UnityEngine.Vector3[] o_resultNorms, UnityEngine.Vector3[] o_resultVels) (at Assets/Crest/Crest/Scripts/Collision/QueryDisplacements.cs:61)
DWP2.CrestWaterDataProvider.GetWaterHeights (UnityEngine.Vector3[]& p0s, UnityEngine.Vector3[]& p1s, UnityEngine.Vector3[]& p2s, System.Single[]& waterHeights0, System.Single[]& waterHeights1, System.Single[]& waterHeights2, UnityEngine.Matrix4x4[]& localToWorldMatrices) (at Assets/DWP2/Dynamic Water Physics 2/Scripts/WaterObject/WaterDataProvider/CrestWaterDataProvider.cs:106)
DWP2.WaterObjectManager.Schedule () (at Assets/DWP2/Dynamic Water Physics 2/Scripts/WaterObject/WaterObjectManager.cs:485)
DWP2.WaterObjectManager.FixedUpdate () (at Assets/DWP2/Dynamic Water Physics 2/Scripts/WaterObject/WaterObjectManager.cs:230)
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Bad indices/count arguments (managedBufferStartIndex:0 computeBufferStartIndex:0 count:4719)
UnityEngine.ComputeBuffer.SetData (System.Array data, System.Int32 managedBufferStartIndex, System.Int32 computeBufferStartIndex, System.Int32 count) (at C:/buildslave/unity/build/Runtime/Export/ComputeShader.bindings.cs:166)
Crest.QueryBase.ExecuteQueries () (at Assets/Crest/Crest/Scripts/Collision/QueryBase.cs:423)
Crest.QueryBase.Update () (at Assets/Crest/Crest/Scripts/Collision/QueryBase.cs:403)

I will check this on Friday when I am back in office. Crest probanly caches something on their end whoch causes the problems. Supplying different i_ownerHash could solve the problem.

OK thanks, I did a little bit of digging, haven’t found a solution yet, but it looks like Crest has an array that’s sized at 4096. Then when synchronize gets called it’s mistakenly(?) appending to the sample count. I tried changing the owner hash and also calling a remove function that’s on the coll provider, neither seemed to work. Might need to put up an issue in the Crest repo.

I ended up adding a deinitilize hook to the water provider class. So it calls deinitialize and then initialize again. I did this to fix an issue with leaking water sample classes with UWS when calling Synchronize, It’s possible that calling initialize again is breaking the Crest integration. Let me check that tonight.

Edit: Yeah, looks like you can disregard the above errors, I reverted the changes I made to the WaterObjectManager and the Crest integration seems to be working fine.

Actually I’m still having problems with this.

I currently have a WaterObjectManager that gets set to Don’t Destroy On Load, so it persists across scenes. Now what happens is that my main menu scene queries heights correctly, but as soon as I switch to another scene with its own Crest OceanRenderer, the height queries stop working.

So I tried putting a WaterObjectManager in each scene and disabled the Don’t Destroy On Load script, but now when it loads, I get the error messages that I pasted earlier and everything falls through the water.

It seems like re-creating the CrestWaterDataProvider is causing issues, however if it’s not re-created it doesn’t get a reference to the new OceanRenderer and doesn’t query any heights.

Edit: I came up with a workaround. It seems the ring buffer in Crest’s QueryDisplacements needs to be reset. The only way to do this currently is to cast the collProvider to QueryDisplacements and disable then immediately enable it. I added a Synchronize method to the Crest DataProvider that gets called when Synchronize is called on the WaterObjectManager in order to do this. I messaged the Crest Dev on discord about this also.

Edit2: All right, I tried to reproduce in the Demo Scene that comes with DWP2 and was unable (I even added a Synchronize button) and it seems to work fine after increasing the max query count to 8192, because at 4096 it just fails immediately.

But I think the issues with calling Synchronize were self inflicted. I put up an issue in the Crest github about the max query count.

Hello, I’ve just tried setting up a scene for the first time. i have a water object manager, a ship i made myself, a prefab of the motorboat from the demo and a water plane(stylized water) and my ships including the prefab from your demo keep falling straight thru the water. i know engine and rudder work fine. Not sure what im doing wrong. I also have the water tagged as Water.
please help

it also doesnt work when i use the deafault water prefab you included in the asset, but the demo scene works. i cant figure out what im doing wrong

i get the message DWP2: Using Flat Water (Default), im pretty sure i set it up as per the docs, im using unity 2019.2.4f1

It turns out its working but the water plane needs to be at height 0?

1 Like

I bought this pack, and I have a popup that says “First time DWP2 setup” with a set of instructions, but there’s no way to close the popup and it blocks my Unity screen. It comes up when I close and reopen the project in Unity too.

Dev, could you please let me know if there is a fix for this? Your message popup is still blocking Unity.

Still having this issue, and have been unable to use this plugin. Does the dev still support this plugin?

He may not be getting the notices from Unity, I know that seems to happen a lot.
Try getting him through email or PM. I know he is still around and is usually quick on issues.
Website: http://nwhcoding.com
Email: info@nwhcoding.com

2 Likes

Will do, thanks!

1 Like

has anyone had any luck trying to get a character to swim using this asset? Have been working through with Invector character controller and will keep you guys updated, but wondering if anyone has had any luck as of yet

Hello and sorry for the delayed response. For support questions please contact me at nwhcoding@gmail.com as the forums tend to just cut off notifications on one thread without any reason.

Make sure that under Project Settings > Player you have defined “DWP_CREST” or whichever scripting symbol is appropriate for your water. There is a list in the manual of all available scripting symbols.

With the new update this should be fixed.

All the setup steps have been removed and the window too so hopefully that solves the problem.