keijiro / Smrvfx

Skinned mesh sampling with VFX Graph
The Unlicense
1.08k stars 153 forks source link

ComputeShader not set. #25

Closed melMass closed 3 years ago

melMass commented 3 years ago

Hi,

While trying to test Smrvfx in a project it complained about the missing reference (_compute) to the compute shader. Where are you setting the reference?

Also can you explain briefly the logic behind using two files to define the same mono behavior (SkinnedMeshBaker.cs & SkinnedMeshBakerProperties.cs)? Because while in Editor there is a looping missing reference to PositionMap here: https://github.com/keijiro/Smrvfx/blob/5160fe5e92a7e06934bab63c88f76687c6d0a0ac/Packages/jp.keijiro.smrvfx/Runtime/SkinnedMeshBinder.cs#L60

melMass commented 3 years ago

Adding this safeguard does work

if (Target.PositionMap == null) return;

But that should already be handled in the isValid function, my guess is that it's tied to the pattern you used for defining properties but as I have no clue of how it works I cannot debug it further. I'd love to know if anyone knows.

melMass commented 3 years ago

For now, I'm setting up the compute shader binding this way in the Start function of the baker:

_compute = (ComputeShader)Resources.Load("SkinnedMeshBaker");
keijiro commented 3 years ago

When you add the SkinnedMeshBaker component to a game object, Unity Editor sets the _compute property based on the default reference that is defined in the .meta file.

https://github.com/keijiro/Smrvfx/blob/master/Packages/jp.keijiro.smrvfx/Runtime/SkinnedMeshBaker.cs.meta#L11

So, it should work properly if you add the component using the Editor.

If you add the component by scripting (like AddComponent<SkinnedMeshBaker>()), it doesn't work. In that case, your workaround suggested in the last comment makes sense.

Also can you explain briefly the logic behind using two files to define the same mono behavior (SkinnedMeshBaker.cs & SkinnedMeshBakerProperties.cs)?

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods

keijiro commented 3 years ago

I'm closing this issue now. Please feel free to reopen it for further problems.

melMass commented 3 years ago

Thank you very much!