x


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!

more ▼

asked Nov 30 '09 at 08:49 AM

yyy450 gravatar image

yyy450
64 2 2 4

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Nov 30 '09 at 09:15 AM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

Thanks! Can you tell me the detail about the security? I can not understand it.

Nov 30 '09 at 09:37 AM yyy450

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.

Nov 30 '09 at 11:11 AM jonas echterhoff ♦♦

Thanks very much for your answer!

Dec 01 '09 at 01:25 AM yyy450
(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered Nov 30 '09 at 10:00 AM

jashan gravatar image

jashan
10.3k 25 43 117

dear jashan! you always answer questions as well as possible you can not use C++/CLI on MONO. 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 SDK 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.

Nov 30 '09 at 05:27 PM Ashkan_gc

Thanks! I will try to use C# or .NET-version of C++.Is it only allowed in the pro version of unity?

Dec 01 '09 at 01:28 AM yyy450

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).

Dec 01 '09 at 02:59 PM jashan
(comments are locked)
10|3000 characters needed characters left

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 http://dot.net assembly and I assume that performance wont be different as calling regular c#? Is that right?

Thanks

more ▼

answered Nov 30 '09 at 03:30 PM

stubbornmoose gravatar image

stubbornmoose
54 3 4 11

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 Mono) ... however, I think that would be a separate question ;-)

Nov 30 '09 at 04:01 PM jashan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x408
x20

asked: Nov 30 '09 at 08:49 AM

Seen: 3436 times

Last Updated: Dec 24 '09 at 10:16 AM