Unity C# plugin project conversion

I’ve been busy with Unity for the last 2 1/2 years and have grown quite accustomed to how C# works. To be honest, before Unity, I have never done anything in OOP (I’m an old-school linear Pascal/PHP programmer) and using C# gave me enough handles to understand the OOP concept.
That being said, the plugin project I’ve been working on for Unity is one that uses a lot of classes and derivation of them along with a HUGE number of lists.

In Unity it’s no problem just to make some code (classes) and use them in the main game’s programming code. Now the recent change to Unreal (thanks to our lead developer :stuck_out_tongue: ) kinda forces me to convert the code I’ve written so far for C# (274Kb total) into C++. And that’s where things go bad for me. I have no real knowledge of C++ and how Unreal handles it.

Let me show a snippet of code I’ve made in C#:

public enum d20Skill { Balance=1, Bluff, Climb } // and a whole lot more!

public class d20SkillProperties  {
	private d20Skill mySkillName;
	private d20Ability myKeyAbility;
	private bool myTrainedOnly=false, myArmorCheckPenalty=false;

	public d20Skill SkillName {
		get { return mySkillName; }
		set { mySkillName=value; }
	public d20Ability KeyAbility {
		get { return myKeyAbility; }
		set { myKeyAbility=value; }
	public bool TrainedOnly {
		get { return myTrainedOnly; }
		set { myTrainedOnly=value; }
	public bool ArmorCheckPenalty {
		get { return myArmorCheckPenalty; }
		set { myArmorCheckPenalty=value; }

public class d20Balance : d20SkillProperties {
	public d20Balance() {

…yes, I’m coding the d20 RPG system here…

I have dropped this same code into a .CPP file and let MS VS compile it, and had no errors (which I find odd).

My question is what the best way is to convert the C# code I’ve already written and (more importantly) how I have to add it into Unreal. I’ve played a bit with the Unreal engine editor already, and it’s kinda fuzzy for me to see how I can add a simple piece of code to it - all I found was add class, enum and other specific parts of code only.

NOTE: I am aware I do need to get to know C++ and have ordered a very good book to get me up to speed. My guess is that reading/using the book will help a lot, but then still the problem remains on how to implement basic code into Unreal…

I’d recommend following some of the guides and tutorials that are floating around the web.

I actually came to UE4 as a Java developer and have found that porting my old Java code was almost as simple as ctrl+c - ctrl+v…(minor syntax changes were required on some stuff)

It took a short moment to get my head around pointers though, but other than that it was much easier than I thought. I was afraid to dive in for ages but when I finally did I realised I had nothing to worry about.

Good luck :slight_smile:

Thanks for the advice ULLS. Will certainly take a look at the guide. Also that book I mentioned (a getting started with C++, 500+ pages) got in and I’ve started reading it. At page 125 already and though I know a lot already, it’s also showing some of the stuff that’s clearly different from C#, not to mention that I also pick up a couple of tricks to make the code smaller and easier (which is a big help, being auto-didactic :wink: )

@mods - sorry for double post, but the message that it’s under review is so quickly removed that I totally missed it :smiley:

nearly the same shoe here, except I’m converting my stuff successfully :slight_smile:
I’m porting my project from a C based script language, which is for the 1st look close to Unity’s JavaScript, but requiring old styled memory allocations… originally I wanted to move to Esenthel engine, but switched to UE4 immediately when it was released in 2014.

  1. I read through tutorials and other stuff on Tutorials - C++ Tutorials it helper me a lot, and was enough. of course, probably a good book is better and gives you more depth.
  2. then I went through several general and bluepritn tutorials to understand the engine architecture and logic,
  3. and I moved to code tutorials (ue4 programming tutorial and wiki 1st person tutorial) only after getting this knowledge.
  4. started my project and learnt everything on the fly: browsing docs, wiki, engine source, forum and answerhub actively, they are full of super useful information.

I’m sure it was the right way.

The code compiles because it is syntactically valid C++ code. I’m sure you’ll have issues if just copy and paste and expect it to run.

I am a C++ programmer primarily and I’ve read very little in the way of tutorials so take my opinions with a grain of salt, but I find using C++ in Unreal very straight forward. I tend to do the complex things in C++ and then use blueprints to wire things together. I don’t have any hard rules about what I write in C++ and what ends up in a blueprint other than if it seems like a designer’s job it ends up in a blueprint so I do not implement new classes, or new functionality in blueprints.

As an example to create a new enemy.

In the editor create a new class based on Pawn. This creates cpp and h files for the class with a skeleton class and updates the project. In visual studio. I will add additional small classes for behaviors, weapons and whatnot, which can be reused by other classes. Once you have a new class and build the project, you will be able to find your class in the editor amongst Unreal’s classes and use it. For an enemy, I will create a blue print from the class, wire up whatever needs to be connected, place a spawn volume and connect it to my enemy blueprint. It works the similarly for any class you might create as far as I’ve experienced. It’s quite nice actually. The dev team has done a great job of making it all feel cohesive as opposed to a bunch of independently developed, disjointed features like so many other game platforms. Once you really understand how to implement one class, doing anything you want with any other class is simple.

Your best friend will be the online class reference. Personally, I’m not a fan of cascading class structures like the way Unreal is designed but it is very easy to comprehend and find what you need when venturing into new territory implementing new classes.