- Home /
Can I use the c++ plugin for the browser-based game?
I have my librarys built in c++ such as AI, and want to use them in my browser-based game. But I notice the information in the document:
Unity Manual > Advanced > Plugins - Pro only feature
Unity has extensive support for C, C++ or Objective-C based Plugins. Plugins will work in standalones only. They are disabled when building a Web Player for security reasons.
Is it means that Plugins cann't be used in the browser-based game? Thanks!
Answer by jonas-echterhoff · Nov 30, 2009 at 09:15 AM
Yes, you cannot use C++ plugins in browser based games. Allowing this would mean people could execute arbitrary C++ code on any user's machine, which would be a very big security hole. You can you managed C# dlls in the web plugin, though.
Thanks! Can you tell me the detail about the security? I can not understand it.
See Jashan's comment below. Basically, giving developers access to C++ code, would allow making a malicious web site, which can access/delete files on the user's hard disk, crash the browser, access other connected hardware, just by having the user visit the web site. That is not acceptable.
@cowlinator:
A webGL build is even more restricted as you can only use interfaces which has been made available and everything that might be a security problem is not allowed. The UnityWebplayer allows slighly more things as the webplayer itself is a native plugin. So the webplayer plugin itself could execute any code on the client but it has been developed by a trusted company. Content that is viewed with the webplayer is something that is generally not trusted.
Here you see a list of things that are not supported when targetting webGL.
Answer by jashan · Nov 30, 2009 at 10:00 AM
The problem with security would be that a malicious developer could basically develop a virus and spread it as a Web player, if he had access to C++ plugins from the Web player. With the integrated Mono-framework used for scripting, anything that could be harmful to the enduser's machine can comparatively easily be prevented ("sandbox"). Doing that for C++ plugins would be extremely hard (if not impossible), and it would take away the most important thing C++ plugins are used for: accessing hardware that isn't otherwise accessible.
You have one alternative, though: There's also a .NET-version of C++. Maybe you can compile your libraries to .NET assemblies and use them from within your game (that's possible with Web players).
dear jashan! you always answer questions as well as possible you can not use C++/CLI on $$anonymous$$ONO. you can use it on mono for windows but it will not work on macs because it's mix mode assembly and (native code and CIL) it's possible to generate CIL only assemblies but it's too hard to do so. see faq http://www.mono-project.com/FAQ:_Technical mono-c++ http://www.mono-project.com/CPlusPlus there is an exe file in .NET SD$$anonymous$$ that tells you if the code is managed only or not. also you should use /slr:pure or /clr:safe flags to generate pure managed codes.
Thanks! I will try to use C# or .NET-version of C++.Is it only allowed in the pro version of unity?
As long as you have .NET assemblies, you do not need to Pro version of Unity. However, if I understand Ashkan correctly, it may not be as easy as I originally thought (so be sure to check the links he posted in the comment above).
Answer by stubbornmoose · Nov 30, 2009 at 03:30 PM
I remember reading something about performance degradation for managed to not managed calls. How bad is it?
When I implement a managed c++ project, it becomes dot.net assembly and I assume that performance wont be different as calling regular c#? Is that right?
Thanks
Yes, that's right: A managed c++ project would not have the overhead of p/invoke (not sure if it's also called p/invoke in $$anonymous$$ono) ... however, I think that would be a separate question ;-)