Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The title kind of says it all. Is it possible to replace C# with C++ on a game using Unity?

share|improve this question
    
It is if you have the Pro edition. For more information see: docs.unity3d.com/Manual/Plugins.html – Ascendion Aug 27 '14 at 3:12

2 Answers 2

up vote 17 down vote accepted

It is possible to use C++ with the Free version of Unity, although it is easier to work with if you have a Unity Pro license. All you have to do is wrap it up in a DLL and follow the instructions below on where to place it.

I wrote an article that covers this topic: Unity and DLLs: C# (managed) and C++ (unmanaged)

For Unity 4 Free:

  • Add unmanaged code to the Unity Project Root: UnityProject
  • Add managed code to the Plugins folder: UnityProject->Plugins
  • When you build a project, copy the unmanaged code to BuildRoot->Data->Plugins

For Unity 4 Pro and any Unity 5:

  • Just copy the DLLs into UnityProject->Plugins

Unmanaged means C++ and Managed means C#

share|improve this answer
1  
Has this changed for Unity 5 where the free version contains all of the engine features of the pro version? – GeekyMonkey Mar 4 at 12:33
1  
@GeekyMonkey Updated the article and answer. – MLM Mar 4 at 18:55
    
Thanks for that. Great news. – GeekyMonkey Mar 5 at 22:47
    
It makes no sense to try to replace C# with C++ in the Unity3D context. This answer may be helpful if interfacing with native code was asked for. – Code Clown Jun 24 at 10:42
    
With the new IL2C++ technology, there aren't many reasons to use C++ instead of C#. Right now, it's limited to mobile platforms but expect the tech to soon be available on PC. – JPtheK9 Jul 4 at 8:03

It is possible though inconvenient. You'd have to write managed C++ to achieve it. And yes, there is such thing as managed C++. Managed doesn't specifically mean C# and unmanaged C++. To achieve it you'll need to import UnityEngine DLL file. When you're finished you put it in the (Unity Project Name)/Plugins folder. Here would be the code you'd use: In the C++ file:

public ref class CPPUNITY {
  public:
     void Start() {
         Debug::Log("C++ printed message");
     }

};

In the C# file:

     using UnityEngine;
     public class FileName {
         void Start() {
              CPPUNITY.Start();
         }
     }

That exact code wouldn't work but thats a base.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.