Conversion - C# to C++

Hello everyone. Since the release of UE4 & CryEngine to the public, a lot of Unity devs (as myself) have considered switching engines. I was wondering if it was possible to convert the source code for my game to C++ so that I would be able to make a smoother transition. I was also wondering if networking would be similar to that of Unity (I read somewhere that it also uses RPC’s) or if I needed to do a complete conversion there as well. I can post a sample of some script which probably wont make much sense, but at least it shows how networking calls are made in our game:



public void OnJoinedRoom()
	{
	inLobby = true;
	if(MatchStarted == false)
		{
		MainMenuGUI.Instance.ToMenu("Lobby");
		Debug.Log("Switching to lobby");
		}
	transform.GetComponent<PhotonView>().RPC("Server_PlayerJoined", PhotonTargets.MasterClient, PlayerName, PhotonNetwork.player, false);
	Debug.Log("Joined Room");
	}

[RPC]
public void Server_PlayerJoined(string Username, PhotonPlayer id, bool isReady)
	{
	transform.GetComponent<PhotonView>().RPC("Client_PlayerJoined", PhotonTargets.All, Username, id, isReady);
	}


Not sure though but maybe you can give this a try:

Would I need visual studio express or something like that to run it?

You need VS2012 or higher to compile your projects.

Honestly I would start out from scratch and use your C# LOGIC as reference. I firmly believe that learning C++ makes everything else much easier to understand in UE4. I suffered from extreme information overload and considered going back to Unity until I sat down and decided to focus on learning the API and recovering my basic knowledge of C++ (haven’t coded in C++ in over 10 years)

In Unity you drag and drop objects onto variables in the Editor to create references (Their Object iteration sucks and Find is slow).
In C++ you create pointers or Iterate through objects of different class types.

Also please for the love of god look into your formatting :D… Don’t tab your {}'s over like that it drives me nuts.

While it’s possible to convert C# to C++, its impossible to convert from one engine to another (without having a very complicated tool to do this, which do not exist). But relatively easy to port (if you know C++ and UE4 API) since you already have the algorithms and logic.

Network in UE4 uses Replication and RPCs.

I will tab my {} as much as I want xD Besides, it makes code a lot easier to read and see where each line ends (in my opinion). Yeah I might have to start from scratch, which will probably be the reason that I won’t be switching to UE4 any time soon (at least not for a paid subscription). Will UDK be upgraded to being powered by C++ rather than Unreal Script? Because that way I could get some practice and have a better understanding of what lies ahead of me.

Pay $19 or whatever to learn the tool and turn off the sub. Problem solved. Not trying to sound harsh but back when Unreal '99 (Unreal Tournament, whatever year that was) came out I paid full price for that thing which was at least $50. Got my start making mods in it

If you are not willing to invest then it’s fine to stick with Unity Free. Sounds like you are pretty far along anyway.

I have no problem with investing actually and I am considering it. Just feels like there is a distinct lack of documentation for Unreal C++ and that if I get it now, I will have a fairly bugged version of the program. But yeah, I can see what you mean. Thank you everyone for your tipps!

From a quick glance, that appears to convert C# to C++/CLI not straight C++. C++/CLI is effectively the C++ dialect of C# for .Net. Great for doing plumbing work for managed languages but it won’t help in this case because it still needs to run on the .Net run-time and expects a GC.

The syntax between C++ and C# is very similar so there is some scope for automatic conversion of logic and class hierarchy but the main problem is the change in memory models. Even a successful syntactic conversion leaves you a nightmare of a big lump of code that allocates memory all over the place and never frees it.

You really need to redesign your code for the change in memory management models between C# and C++.

I have ported a lot of code in both directions in the past and its not too bad really. Get some strong coffee and be prepared to write a few regexes in your editor for common replacements and you can motor through the code pretty quickly. It becomes quite meditative. Oh and make sure you have a test suite!

I have written a few tools to help port from C# in the past using NRefactory. I may adapt one to help with Unity conversions.

I would pay for that!
That is exactly what I am doing today…I just need a couple core physics scripts, both physX 3.3…
I wanted to experiment, how quickly can I get a full mobile game ported?..
Using code to connect to BP for Editor Configuration, seems to be the best way…

but a little tool like that may be real handy…, more zen like…

Patrick

patrick