Page 1 of 1

ONE Way for combine CSharp and CPlusPlus in the One Project ?

Posted: Mon Apr 16, 2018 1:04 pm
by ahmad0karami
Hi guys,

I used DLL files ( Windows-API ) in the Visual Basic.Net / VB6 , Now consider to that model of behavior.
I Know C#/VB.Net , both , I can use in the Application Projects.
Is possible , I use c++ and c# ( both ) in the One Project in the CryEngine 5.4 or 5.5 ?
There is a way for do/use/import both cpp/h and cs ( Source code *.cpp / *.h / *.cs ) or DLL ( *.dll files ) in the CryEngine 5.4 or 5.5 for games?

Thanks

Re: ONE Way for combine CSharp and CPlusPlus in the One Project ?

Posted: Mon Apr 16, 2018 4:14 pm
by Cry-Miron
You can combine managed and native plugins in the same project. The only part that you need to watch out for is that generating a solution can get weird.

The easiest way to combine C++ and C# in one project is to use the C# assets in the Asset Browser of a C++ project. This will create a new managed plugin that will be automatically handled by the Sandbox.

The other option is to make a new C# or C++ project from the plugin template in the launcher. Next you want to move the .dll files of the plugin to your game project and specify the location of the .dll file in the cryproject file like this:

Code: Select all

[...]
"require": {
"engine": "engine-5.5",
"plugins": [
{ "type": "EPluginType::Native", "path": "CryDefaultEntities" },
{ "type": "EPluginType::Native", "path": "CrySensorSystem" },
{ "type": "EPluginType::Native", "path": "CryPerceptionSystem" },
// This is the original game plugin. This a native plugin made with C++.
{ "type": "EPluginType::Native", "path": "bin/win_x64/Game.dll" },
{
"type": "EPluginType::Native",
"path": "CryGamePlatform",
"platforms": [ "PS4" ]
},
// This is the managed plugin made with C# which is from a different project.
// Make sure the value of "path" is set to the correct file, and that the .dll file is copied to that location.
{ "type": "EPluginType::Managed", "path": "bin/Plugin.dll" }
]
},
[...]
In case that you copy the above example, don't forget to remove the comments because they will invalidate the JSON.

Keep in mind that by default it's not possible to easily call native functions from managed code, and the other way around. At the moment you would have to set this up yourself if you require this functionality.

Re: ONE Way for combine CSharp and CPlusPlus in the One Project ?

Posted: Mon Apr 16, 2018 6:39 pm
by ahmad0karami
yes , i know this idea get weird ,a example for use C# UI Library in the C++

using CryEngine.UI;
using CryEngine.UI.Components;

I think , in this time , my idea is good , of course , maybe good ;-)

Re: ONE Way for combine CSharp and CPlusPlus in the One Project ?

Posted: Sat Apr 28, 2018 1:38 pm
by Melvasul
This really interesting.
I think I've done it correctly but I get an error

folder view
Image

code view
Image

loading error
Image

I created a C# project
Transferred the plugin
hope to do everything alright

if I try to open a C# file created in the sandbox I get the error
"devenv.exe not found"

Re: ONE Way for combine CSharp and CPlusPlus in the One Project ?

Posted: Wed May 02, 2018 12:39 pm
by Cry-Miron
It looks like you're missing the path to you C# game.dll in the plugins list. You also don't need to add CRYENGINE.CSharp.dll to your plugins. That dll is the Sandbox plugin that will be automatically added if you have C# files in your assets.

So you game plugins will need to be set like this:

Code: Select all

"plugins": [
{ Other plugins },
{ "type": "EPluginType::Native", "path": "bin/win_x64/Game.dll" }, // <- This is the C++ plugin
{ "type": "EPluginType::Managed", "path": "bin/Game.dll" } // <- This is the C# plugin
]