Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to make it work in Unity 2019? #8

Closed
AgrYpn1a opened this issue Jul 9, 2021 · 7 comments
Closed

Is it possible to make it work in Unity 2019? #8

AgrYpn1a opened this issue Jul 9, 2021 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@AgrYpn1a
Copy link

AgrYpn1a commented Jul 9, 2021

Hey, I am having trouble using this in Unity 2019, there is an error in the Unity Collections dependency package, something about ReadOnly missing from the NativeArray.

@psydack
Copy link
Owner

psydack commented Jul 9, 2021

Hello there.

I think the error you're saying happens because the original it uses a NativeArray to do some render stuff, like this:

// RendererMesh.cs or RendererProcedual.cs
// ... line160
// TODO: Convert NativeArray to C# array or list (remove collections).
NativeArray<ImDrawVert> vtxArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<ImDrawVert>(
	(void*)drawList.VtxBuffer.Data, drawList.VtxBuffer.Size, Allocator.None);
NativeArray<ushort> idxArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<ushort>(
	(void*)drawList.IdxBuffer.Data, drawList.IdxBuffer.Size, Allocator.None);

There is no workaround yet but If you rewrite those lines I'll be glad to merge with the main. =)

Thanks.

@psydack psydack added the wontfix This will not be worked on label Jul 9, 2021
@psydack psydack closed this as completed Jul 10, 2021
@AgrYpn1a
Copy link
Author

AgrYpn1a commented Jul 10, 2021

okay, I've cloned your project directly into the Assets [this way it didn't pull the dependencies] of an empty Unity 2019 Project and it didn't complain about collections, rather it complained about the SetSubMeshes, as it didn't exist, so I had to set the meshes one by one in the loop above:

             // [RenderMesh.cs]
	      for (int i = 0, iMax = drawList.CmdBuffer.Size; i < iMax; ++i)
	      {
		      ImDrawCmdPtr cmd = drawList.CmdBuffer[i];
		      SubMeshDescriptor descriptor = new SubMeshDescriptor
		      {
			      topology = MeshTopology.Triangles,
			      indexStart = idxOf + (int)cmd.IdxOffset,
			      indexCount = (int)cmd.ElemCount,
			      baseVertex = vtxOf + (int)cmd.VtxOffset,
		      };
		      descriptors.Add(descriptor);
                      // This line HERE *********
		      _mesh.SetSubMesh(i, descriptor, NoMeshChecks);
	      }
      
	      vtxOf += vtxArray.Length;
	      idxOf += idxArray.Length;
      }
  }
  
  _mesh.UploadMeshData(false);

image

Now, I am not sure, but it appears that collections used are there by default in Unity 2019, maybe they separated it into a package later to make Unity lighter, so I am thinking maybe we could just modify this part of the code, and add a conditional package dependency based on Unity version, not sure if that's possible?

@AgrYpn1a
Copy link
Author

AgrYpn1a commented Jul 10, 2021

Alright, I got it working without the NativeArrays.. I do not think it's the best way as it possibly affects performance but I can't tell how much.. plus I don't think there's another way.

[NOTE] Not sure if it's something local, but I first went and just removed the Collections package and it worked in 2019 after modifying what I wrote in a comment above, then I run the same project and upgraded it to 2020 and it was still working without the package. Are you sure you need that dependency?

Here's a screenshot of everything working with FPS, I'll do a pull request and then decide whether or not you want to use it, meanwhile I'll for the repo because I need this asap.

image

@psydack
Copy link
Owner

psydack commented Jul 10, 2021

Wow, nice!

I'll test this into a different branch.

[edit]
You're right, we don't need the collections package. ;)

Thank you for your effort.

@psydack psydack reopened this Jul 10, 2021
@psydack psydack added enhancement New feature or request and removed wontfix This will not be worked on labels Jul 10, 2021
@psydack psydack self-assigned this Jul 10, 2021
@AgrYpn1a
Copy link
Author

So to sum up...

I did some more testing, there are some more issues, for example while the code I wrote there fixes the compile error and it seems to be working, some parts of imgui features do not work as expected.. not sure if I can further investigate, however this concerns only the Mesh rendering type, you can go fine with Procedural.

About the NativeArray issues, I believe you can freely get rid of the dependency, test it out with your version of Unity to be sure, but here it works fine without it, because it's a built-in feature of Unity.

And that's pretty much it, in the end we just gotta fix that compile error and get rid of the dependency.

@psydack
Copy link
Owner

psydack commented Jul 10, 2021

The original goal doesn't include the 2019 support, so I think the best way is to rip off render mesh for < 2020.

Thanks again!

@AgrYpn1a
Copy link
Author

Sure, that will be quite enough! :) and np, doing this because I also need it hehe, might hear from me again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants