Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

If I use a C# coding in Unity 4, can I transfer that coding into another non-Unity engine as long as it accepts C# too? I hope this question makes sense. Thank you in advance.

share|improve this question
1  
You sure that it's C++ not C#? –  joltmode Mar 24 '13 at 13:24
    
Unity does not support C++ for scripting. You can use only C# or Javascript (and Boo?). –  Jaakko Lipsanen Mar 24 '13 at 13:32
    
You can write plugins for Unity in C++ assuming you're using Unity Pro. But this might not be what Lana Tisdel was referring to. –  Alex M. Mar 24 '13 at 13:45
    
This question cannot be answered completely. If you are referring to C++ code without dependencies you could transfer that into any other environment which supports C++. But if you rely on dependencies you have to move them, too. And you rely on the Unity API you cannot use the code without that. Therefore you would have to modify the code to use own implementations for Unity functions. –  danijar Mar 24 '13 at 14:25
    
@psycketom, Okay, sorry about. C# or Javascript. Also, O don't have Unity Pro, I've got the free version for now. Thank you for trying to answer my question everyone. I got Negative 3 on here? What does it mean? –  Lana Tisdel Mar 24 '13 at 17:54
show 1 more comment

4 Answers

up vote 3 down vote accepted

It depends on WHAT exactly you'd like to 'transfer' (or port). This is really just a simple library dependency matter. I'll try to put it simply. Suppose you have a class:

class AnimatedCharacter : MonoBehavior
{
     public GameObject SomeObject;
     // more code here
}

Can you just take this class, add it to another project that's developed under a different engine, and expect it to work? If you don't have a definition for GameObject in the destination project, and there's no MonoBehavior class to inherit from, then the answer is "NO". Here, GameObject & MonoBehavior are data types typical to Unity, and won't be recognized by any other engine.

class PairOfInts
{
   public int Element1;
   public int Element2;
}

This on the other hand has nothing to do with Unity's stuff. It will be compiled without a problem by any C# compiler and thus, it will work under any project you might be thinking to add it to.

In short: any code that works directly with Unity's own data types and/or functionality (inspector view things for example) will not work as expected (if at all) under another engine.

share|improve this answer
    
Very informative. I get what you are saying. –  Lana Tisdel Mar 24 '13 at 21:32
add comment

It sounds like you're a beginner, and are concerned with investing time in a tool and not getting any transferrable skills out of it.

The most valuable thing that Unity3d is teaching you isn't C#. It's teaching you how to work with a 3D game engine. Working with vectors, thinking about your asset pipeline, and how to translate input from a player into interesting transformations on screen that they can then use to accomplish some goal you set forth for them.

Don't concern yourself with code reuse. I'm still working off of the assumption that you're a beginner, so you likely won't have enough code to justify being serious about code reuse, and having to re-implement some feature or translate it from C# to another language is good for you.

Switching languages/toolsets as you evolve as a game developer opens your mind to new ways of doing things, earns you greater understanding of past problems you've already solved, and enables you to evaluate the quality of your future ideas for solutions to problems.

share|improve this answer
    
Thanks a lot, Michael. That's a more positive way of looking at it. –  Lana Tisdel Mar 24 '13 at 21:34
add comment

In short the answer is yes but there may be many things you will have to refactor or re-implement entirely. The more you depended on Unity's libraries, the more you'll have to modify.

share|improve this answer
    
That makes sense. Good point about the "libraries". Thanks! –  Lana Tisdel Mar 24 '13 at 21:45
add comment

Maybe. Any bits of code that only rely on standard C# constructs will be fine. Code that directly uses Unity APIs (including all the custom math libraries) will not be directly portable to another engine.

In general (for any language or engine), you can reuse most game logic code between engines, but it takes work to port it between APIs. It's often not worth it. The hard part is figuring out what the code should do to achieve desired results, not writing the code itself. It can take less effort in many cases to rewrite the code than to port. Depends on the circumstance of course.

share|improve this answer
    
Hmm, interesting perspective, Michael. –  Lana Tisdel Mar 24 '13 at 21:36
add comment

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.