Closed David20321 closed 3 years ago
As far as I remember unity has its own imgui implementation which is pretty similar to this one. So I don't see any point of it. Their whole editor is built with it.
I believe their internal implementation that they use for the editor is not exposed for use in games -- they only expose this system which is much less powerful than Dear ImGUI.
As far as I remember it was pretty similar but its your time man do whatever you like :)
You can use the Unity's IMGUI in game. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html
And it's much powerful than Dear ImGUI. Because Dear ImGUI is one pass, but Unity's OnGUI
is like WinProc
. In OnGUI
there is a Event.current
to indicate what to should do, then the system can percisely know what you want to do.
Is this the complete list of all imgui-style Unity controls? Labels, buttons, textfields, sliders, checkboxes and windows. https://docs.unity3d.com/Manual/gui-Controls.html
I would like to use nested menus, tooltips, trees, graphs, multiple controls per line, and so on.
I would also like to see this attempted. Unity's ImGUI implementation leaves a lot to be desired, especially after having used Dear ImGUI.
I'd be interested in this, mostly because Unity IMGUI API has garbage generation issues. Not sure if this was fixed recently though.
Has really nobody tried this yet? 😱
@David20321 ended up doing it himself it seems: https://twitter.com/Wolfire/status/1057060079483011072
Maybe he'll share the tech!
I am currently attempting this myself and have already hooked into the rendering pipeline. Unfortunately though I am not experienced with DirectX11, hence I wasn't able yet to get ImGui to render properly. Will update you guys if I happen to be successful.
EDIT1 Quick update after an hour into experimenting with the integration.
You might see the very small window on the top left - for some very weird reasons it it only visible when I have the context menu of the Game view open; otherwise, not.
At least this is an indicator that I am doing at least something right. As mentioned before though, I have never used low level graphics APIs and will definitely need a lot of time since I am getting this done via trial-and-error.
EDIT2 It seems that Unity clearing the screen and thus not rendering the ImGui window unless I open the context menu which actually pauses execution of the game which makes the ImGui window visible all of a sudden.
EDIT3 Here is a topic I just created for the issue if someone of you wants to chime in to get this issue fixed.
EDIT4 I already managed to fix the issue which was indeed a wrong order of draw calls. Now it renders almost correctly:
However the window has a very weird size, doesn't resize to its contents and cannot be interacted with. Most likely this is an issue with the mouse handling as well as the inability to fetch the window handle of the game window. I will try my best in the next few days after seing that it is indeed possible :)
Well call me stupid, I completely forgot to hook the Unity WndProc in order to call the ImGui Win32 WndProc that is being supplied in order to handle input: https://www.youtube.com/watch?v=EqqXp8S62Rw
Unfortunately I am still having two issues:
Very nice work so far! Will you put the sources for this on GitHub soon?
Once I'm able to wrap my head around hooking into the Editor itself (mouse click events are still not processed in Play mode, only in the standalone variant) I can definitely write a summary on how to integrate imgui into Unity and share the necessary snippets.
The problem is mainly, that Unity is really weird with regards to native plugins and on top of that I am having my code in an entirely different library that my managed code dynamically loads using LoadLibrary instead of extern definitions using DllImport. What it really comes down to is that the actual implementation will differ for each use case since it's quite difficult to interop between C# and C++ unless you write everything (even the game code) in C++ as I do. I really think, unlike other wrappers, this won't be as easy as dropping a DLL and having access to it right away 😄
Ah, fair point. I think for it to work well in C# you'd have to write interop functions for cimgui, and then probably write the rendering manually in C# as well.
I'd like to announce that I managed to fully inject imgui into Unity, both for standalone games and the Unity editor itself: https://youtu.be/LXd33Bs3JWY
In the end I was able to find the corresponding handles of the Game view window (thank you Winspector Spy, you never cease to amaze me) and with some tweaks I am able to differentiate between a standalone build and the in-editor one.
One of the caveats is that for some reason ImGui stops to render once the Game view is maximized using the context menu command - I can just assume for the time being that a different swap chain or something akin to this is created onto which I am no longer drawing at that point.
Furthermore another caveat is that imgui breaks the way I hot reload my native DLL into a running game in the editor. This is just an issue on my end due to the architecture and nature of the project, which I should be able to fix nonetheless.
I will be looking into explaning the steps I had to take in order to inject this properly (unfortunately I had to do some minor tweaks to the imgui sources themselves to handle the editor) in the upcoming days, once I'm in the mood for it 🤣
In the hopes of getting some positive feedback I jumped in the shark tank over on Reddit: https://www.reddit.com/r/Unity3D/comments/9wevmn/wip_integrating_dear_imgui_into_unity_a_small/
@ghost I checked out the video, that looks great that you have it running.
Reddit page looks dead now. Did you ever release this? I agree it would be great to get this working in Unity. I have used Dear ImGui a fair bit and just on a quick glance I can tell that Unity's built in IMGui stuff is going to be a bit of a pain to use, just with having to specify the dimensions of buttons and such, and doesn't look like it has windows in the way that Dear ImGui does.
In your use case are you able to write ImGui calls from C# game code, or did you avoid that because you have your game code in a native C++ DLL? For my purposes, I would want to access it from the C# side.
@David20321 and his team have been working on a very complete port of Dear ImGui to the Unity ecosystem (including fully ported C# Demo and various adhoc tools). It's a little late as they had to shift resources to the current game they are making but hoping it get released shortly!
@ocornut @David20321 I'm very much looking forward to this, is any of it on a public repo?
Any updates on this?
Decided to give it a shot myself and (almost) got it to work. Getting close. (Think my material is in fault here)
jup...
I'd say i got about 70-80% of it working but i'll probably be halting development here. If anyone else wants to take it over just comment.
Couldn't help myself from actually fixing it but got it now!
@StijnSimons that's great. Are you planning to open-source your effort? I'm sure all who are following this thread would be interested.
@StijnSimons that's great. Are you planning to open-source your effort? I'm sure all who are following this thread would be interested.
Most of the rendering logic is taken from @David20321 so its up to him. If he agrees; i'll be making it public.
Great work @StijnSimons !
anything yet? :o
anything yet? :o
Got no reply from him on this thread so I don’t know.
I think I found a developer to take on this project seriously but they’ll only be able to start working in February.
I was already working on this for a while, because I got annoyed at seeing people having it working in unity, then never actually open sourcing it themselves :)
https://github.com/JayPeet/UnityImGUI
I'm at the end of my abilities on writing the c++ rendering side of things, and my time is quite limited due to other projects, however it functions with DX11 and allows you to write the ImGui code from the c sharp side of things. However it is just a prototype and is overall quite rough.
Looking for help finishing the project.
We resumed working on that on our side. Here Dear ImGui running in Unity on the Switch over Edgar Bokbok in Boulzac:
Thats awesome news :) Looking forward to checking it out in the future!
Faster. FASTER. :D
Very interested by this ! Thanks for pushing the effort forward
We have been using Dear ImGui in Unity for some of our projects and I finally had the time so separate it into a package.
UPM package https://github.com/realgamessoftware/dear-imgui-unity
Repository for the development project https://github.com/realgamessoftware/dear-imgui-unity-dev
DearImGui
component to one of the objects in the scene.Render Im Gui Feature
render feature to the renderer asset. Assign it to the render feature
field of the DearImGui component.ImGuiUn.Layout
event and use ImGui functions.Example script:
using UnityEngine;
using ImGuiNET;
public class DearImGuiDemo : MonoBehaviour
{
void OnEnable()
{
ImGuiUn.Layout += OnLayout;
}
void OnDisable()
{
ImGuiUn.Layout -= OnLayout;
}
void OnLayout()
{
ImGui.ShowDemoWindow();
}
}
The package uses C bindings by cimgui and the C# wrapper by ImGui.NET.
Some extra functions and overloads were added, mostly dealing with text or images (ImGuiUn.Image()
for Texture and Sprite), as well as helpers to wrap callbacks with try-catch blocks. These can be found in the ImGuiNET/Wrapper.Extra
folder.
This integration uses the Unity rendering API instead of a native plugin for rendering. It works on both the Built-In and the Universal render pipelines and has two renderer types: one using CommandBuffer.DrawMesh and another based on CommandBuffer.DrawProceduralIndirect.
There are 'platform bindings' for both Unity's old Input Manager and the new Input System. Some configuration options such as style, fonts and cursor shapes have corresponding assets and can be edited from the inspector.
And here it is in use by one of our projects:
Known issue: blurred on Universal RP with FXAA.
Very cool @goncalo !
Awesome @goncalo ! I opened up some issues regarding macOS. Not sure if you would fix them as it seems that official Unity support is on the way, but I thought I'd open up the issues regardless 😄
Any compatibility with 2018 version ? When i opened it with 2018 LTS version it says that the assets are serialized with a newer version
Hi there.
Has anyone managed to load and use a font other than the default one? It's not working for me and have no idea what I'm doing wrong.
This is what I do:
var io = ImGui.GetIO();
io.Fonts.AddFontDefault();
var font = io.Fonts.AddFontFromFileTTF( font_path, font_pixels ); // font stored in a dictionary
io.Fonts.Build();>
I checked that the font is properly loaded (.IsLoaded()), but the result is that all fonts get corrupted (even the default one). In this case I'm not even using the PushFont/PopFont pair.
Thanks everyone in advance.
@trapazza I believe you should ask on the https://github.com/realgamessoftware/dear-imgui-unity repository.
Closing this. For Unity-backend related support please refer to https://github.com/realgamessoftware/dear-imgui-unity David's own Unity backend which at some point we considered making official was used on David's project but not released seeing realgamessoftware's solution seemed adequate.
Hi, I'm sorry to necro this thread, but I would want to just ask: what's the status of current support?
I'm asking here because the https://github.com/realgamessoftware/dear-imgui-unity repository was last updated 4 years ago, and there's quite a bunch of unanswered issues, so I don't believe that asking there is going to yield any kind of answer.
Is this officially over and nobody is working on making available ImGUI in Unity?
There’s another backend listed in Wiki which apparently has been updated 3 months ago.Bindingsgithub.com
@ocornut Looks like your link got eaten.
To save others from tracking things down:
Has anyone tried integrating Dear ImGUI into Unity? It seems much better than any of the other UI options for Unity in my experience. If not, if I did that would it be ok to sell a wrapper for it on the asset store?