Monogame in Xamarin / .NET Maui

Is there an actual way to use both Xamarin Forms and Monogame together? I want to create a 3D editor of sorts using a Monogame 3D sub-window for the 3D space, and Xamarin for the UI (like the Unity editor for example). Can I do this with Monogame, or should I use a different 3D engine for Xamarin. If so, any recommendations?

Just use Monogame.forms

I was able to do this with native Xamarin.Android, Xamarin.iOS and a fork off MonoGame 3.71:

The biggest problem is that MonoGame is really sloppy about cleaning up after itself, I had to fix a ton of bugs related to shutting down and restarting new instances of MonoGame in the same app. Also the architecture of MonoGame.iOS is a nightmare, I had to add factory methods 3 layers deep just to subclass the monogame viewcontroller, and sorting out the touches & gestures is a complete headache.

It turned out pretty awesome though, I used it for a note-taking app ScatterNote.com
Everytime the user opens the notebook view, it’s a new instance of MonoGame with native Android & iOS controls layered on top.

Also the recommendation MonoGame.Forms is wrong, that’s for embedding MonoGame in a WinForms project, not Xamarin.Forms.

3 Likes

Are there any tutorials or guides for using this fork? I want to make a multi-platform editor with Xamarin UI and Monogame as a 3D view in the middle (or any other good 3D engines compatible with Xamarin)

Afaik Not really. I’m still trying to find a way to render stuff onscreen before compiling myself.

Just use ImGUI. It’s definitely better than whatever mgforms is, and specializes exactly on making editors.

1 Like

Yeah I’ll go ahead and spin up a really basic HelloWorld that can spin up MonoGame inside a Xamarin.Android and Xamarin.iOS app, and then another full-blown MVVM example that uses ReativeUI to move all the business logic into a viewmodel.
Once that is up and running, I can start working on getting these changes rolled into the main MonoGame repo.

The end result of all this is that you end up with a native Android and iOS app, with MonoGame running in the middle of it. The recommendation to use ImGui might work on mobile, but the end result UX definitely doesn’t match Android & iOS. If you plan on putting something on an app store, I wouldn’t use imgui, iOS users in particular get upset if an app doesn’t follow Apple’s best practices. YMMV

1 Like

Has anyone tried using Monogame with .Net Maui? For mobile platfroms? Im using Netcore 6 for everything else but i still suffer with Xamarin. I see that Windows 11 can allow sideloading Android apps , and I hate using the emulator and xamamin in general just takes forever. So im waiting till they sort this all out. Be amazing if a surface ARM can do any app developement for andorid using VS Code. I read that microsfot is working on “partical emulation” and native ARM JIT compiling … because they wanna self ARM Surface Pros that don’t blow hot air out both sides like mine does. .NET MAUI Finally Replaces Xamarin in Visual Studio 2022 17.3 Preview 1 -- Visual Studio Magazine

I have not. Since the time I started this thread, I have come across web development and have found that engines like three.js are very good for making games or really anything. It is all code-based and has allowed me to mix the standards of web dev (html, css, and js) with a three dimensional engine. You could make a .NET blazor app which has a web view in it. The inner site can be treated as either a website or a hybrid web app which can allow you to make pretty much whatever you want (web application, etc). I am making editing software for something and I now have a 3D preview mixed with html elements. The best part about this is that web development is standardized, well-supported, and accessible.

Maybe its perfect for your editing stuff, especialy if there is multplayer but The last time i put a single player high performance game on the web for easy of deploymnt, I had three fundamental problems: business model ( how, where to place ads, whichi are usually paid for by competing similar gamees) and having both Silverlight and Flash blocked for security holes, as soon as they got to be high performance, the risks are gonna be there… Security and permissions on Android is tight, the appstore will take it down if its cloned or found to be malicious, not so easy with a web site. So now im targeting Steam ( for its DRM and that you can by a game for PC and run it on your new Mac also) and the Apple and Android stores since its ok to put ads on those. right now I dont see any securty vulnerabilities wiht the webGL or the Blazor reported yet but java script, lacks most of the type safety, and structures, and performance i need for my game logic so i wount go near it except mabye for UI. Also I want to target consoles if i get traction, since the game works best with a game pad or two.

The best part about this is that web development is standardized, well-supported, and accessible.

Is that sarcasm?

No

anways just the sacasm comment made me want to share a bit more since im getting old and supposed to be wise by now Imagine if you developed graphics or UI or client side code for Flash or Silverlight. for 5 years. Then you get shut down, essentially lose all your front end. in a year are almost inaccessible. i nearly died for trusting microsoft. It is stil psossible to run those but its painful and certainly something u dont wanan update. Be careful. Web tech is temporary. You have to test on tons of browsers. There is no backward compatibilty. The internet breaks and noone barely cares. they intentionally break each other, as go GPU makers. javascript doedsnt have a dictionary last i chacked. you have to debug a typo. webGL might have a future because i dont see how a virus can get from the gpu to the cpu. if most of your code runs on a server I would use those kind of things otherwise a i see a big red flag i’d rather die (again) . HTML and CSS makes me vomit but I do like XAML. now microsfot vs studio 2020 preview runs on ARM and my old WPF app compiles at a netcore app. so i dont hate microsoft anymorebut Im definite glad i stuck iwht C# and forund monogame, pasued 4 years to trust again. even if it took me a year to learn to make a shader or clip a polygon. Just sharing my experience im making a single or two player game thatt needs M< 8 ms latency , and have no cloud experience, so mabye those stacks are ok for a very multi user experience, but now i wont embrace anything new. i wanna build a game peole can run in 20 years … a win32.exe from 1994 can run on windows at least if you have have a CD drive. Aslo you have to pay at least 50 $ a year to host a webpage. you have to pay for the cloud services. thats whwere amazon an d MSFT make their billions now. if yoou publish on app stores, they might host it forever free and do your DRM. yhou can be dead and getting + revenue. software dies… We all gotta die, but i dont wanna code 404 to show up a year after im gone.

You could use Avalonia UI, not sure if it would work with MonoGame.

The thread is a bit old but I want to share some information about mixing monogame and Xamarin.Forms.

First of all, it works.
I have an app inside the App Store, which was created with Xamarin Forms and Monogame for the rendering part.
Only a few adjustments inside the AppDelegate on iOS was necessary, but nothing complicated.

I loaded the game engine and then the forms application.
It was necessary to clear the view colors to see the MonoGame Screen.

That was my app.

Greetings
Ronny

1 Like

@Mampinator

Hi,
cool the app
does your program skeleton work with dotnet Maui?
thanks in advance

I haven’t tried it with MAUI. It was a Xamarin.Forms Project as cross platform project and a platform project (iOS).

If there is a monogame .net core package available, then it should be possible
to add it to a single core project.

With Maui I created a WebGL / threejs Application for the rendering part.
I used the Maui Blazor App Template and added a local three.js library to it.
It worked for iOS and Android. But obviously it’s not MonoGame and only a work around for smaller projects.

Regards
Ronny

thank you for the answer
do you have a basic example
with xamarin/monogame?
my problem is that i know how to link xamarin and Monogame
thanks in advance

I have a multiplatfrom sample… GitHub - damian-666/MGShadersXPlatform: A bare bones, no repeat code, Monogame 3.8 , Net Core 6, with working pixel and other shaders that works in desktop GL and WindowsDX, and Android using shared linked content file, FX files, shared Net6CoreGame lib, and thinnest possible platform specific launchers . this links Xamarin and MG 3.81 and also have desktop targets. You or anyone, Feel free to add a PR for a full page ad host or something. I dont know how to test those outside of GooglePlay and i havent deployed a Beta yet, im sideloading , or usb deploying. Im probably going to ship a game demo Beta built in a similar Solution on Google Play since i have the Google dev license but not an Apple device. But Ios builds and should work with the same shared Game code and MG assets…If you want an adhost for both ios and droid, i’d rather maintain two native ones than one , if that means I have to use Maui again (details below)

I havent got much feedback on XPlatfrom , but its started from an older MG sample that not longer works with MG 3.8.1. it can target ios, windows, osx, linux, and droid, all one one shared code and assets, including shaders.

Silk Windowing looks promising tho, just have seen my first hello Silk.Net Window world on my Phone in secs, not minutes. its a WIP, but I just got basic silk Android sample working via 3 Nugets, and tis 100 x faster to build / deploy, doesnt include any bloat, but still very much a work in progress, very low level and all dependencies are separate. i think we can hook in MonogameGL to GLs rendering Surface, and use rendertarget to it…using Device Service or something as was done for WPF interop. I’ll upload the sample at some point, start a new public project proposed around MG-> silk window host, that bypasses Xamarin, or Maui… and ask for PRs and proposals. I hope MG does not depend on xamarin, i doubt it , thats thats a big XMAL UI platfrom, which is why there is all the bloat, andfor MG I doubt anyone uses use any of excetp to host one window.

I tried retried Maui hello world, the latest, i think its a disaster , even slower and more bloated… I can get a hello world to show only on USB not emulator and its a nonstarter for me.

Re: my MGXPlatfrom , I Tested it via vs 2022 preview on windows, you should be able to clone repo, open the sln, select the Android as the target projectk, right click “set as target project” then contrl f5 and build and run. debug or release. ARM64, or You can stick a phone via usb in there or use an emulator (much slower even with HAXM and windows 11 on a new surface i7)

its always slow to build /deploy / debug/ or package even that simple thing. if you use a phone, pick the Lowest selectoin in the dropdown that mathces your phone, that useplugged in via usb, or it will run the emulator, not on the phone, ( bug in vs 2022). The code is simple it only depends, on monogame, but be careful with leaving your phone in developer mode, it might be less secure.

But with a Maui Hello world and its like 5 + min to build and deploy via usb to a phone, its even slower and its loading xamarin stuff… very disappointing. I get its packing and triming all this stuff… So release build is even slower. But it never deploys to emulator now and takes 20 mintues trying . I have not tried Windows at all, it has to be packaged and deployed via installer, its not like a windows.exe. I dondt See where you would put shared launcher to MonogameActivity. The androidn one has a sort of GAme Activity, but we would want it in ios or all in one place. I think Maui is a not a good path. Im 99.9 % sure never gonna bother putting MG in there, a nonstarter for me. I predict its going to the UWP, windows phone , Silverlight trash bin…

Avalonia UI tho… i will chekc out… i do like XAML… sort of… i regret not using ImGUI tho, for level editing, windowsing, docking, if i had it all to do over…

in conclusion.
Both Maui and Xamarin are this is ridiculous ly slow. To build and deploy and debug. like 1000x worse and netcore on desktop. What i do is develp on windows via touch screen then deploy to android and hope it works. Thats why my shared code thing is ideal for the time being… You can use the same code on a touch laptop as you do for android. only 1000x faster to work with. There are ARM windows Surfaces and ARM dev studio as well ,but MSFT hasnt sent me one yet, despite i promote .net to haters who dont believe its really open source, LOL.

anywasy hope this sample saves you time, and for working together with MG on basic stuff like solutions configurations, and Silk windowing hookup, im willing to host a vault on that. stuff. it looks like SDL is on the backend… Ill upload the Silk sample but i cant promise it can host MG ever. I think it can and will , but This is not my area of expertise at all, hopefulll the Monogame input will work so you dont have to use silk input. they have Audio, but no advertising api bindings. And you can use HLSL / FX shaders, not GL…

1 Like