Apply C++ Xenko scripts code

You know what’s good for the Xenko a script to C++ code in C++ program and many people already have scripts in # what the hell a good alternative to the large, being that the xenko has very much potential and is still in beta phase. So I would like to program in C++ on Xenko.

Thank you Xenko Engine C++ community asks for help

Just so you know, you can already do some compute workload in C/C++ (take a look at the “Native Linking” sample).

However, it won’t give you access to Xenko API from C++ (we’ll need to evaluate if that is even possible – so unfortunately not anytime soon).

Thanks for your feedback!

1 Like

I second the request! The ability to use C++ code with Xenko would GREATLY influence me to make a switch from Unity 3d for my project.

I am surprised to hear that the Xenko API will not be available from C++ since I am aware of at least 3 ways to call native C++ from C#:
C++/CLI
Platform Invoke
Wrap your C++ in a COM object

In Unity 3D, you can write DLLs to use C++ code with the engine.
With all that given, plus the fact that C++ is an industry standard for game development, why would it be difficult for Xenko to be able to use C++?

Thanks.

1 Like

I like this idea as well, as long as performance is not effected. Choice is always a good thing. Unreal uses C++ as a scripting language and I love C++. C# does not bother me like Java or others though.

Unity and Unreal engines are both written in C/C++ whereas Xenko is primarily written in C#. So of course those engines supporting C/C++ is significantly easier than it would be for Xenko.

Xenko uses a number of native (C/C++) libraries under the hood i.e. BulletPhysics. I don’t think there is anything really stopping you from doing similar. But calling the Xenko APIs from C/C++ is a whole other kettle of fish.

Not to mention the fact that xenko does some funky stuff for there micro threading (async) tech. The build process does IL rewriting. I have no idea how they would get the async stuff working with script components written in C/C++.

1 Like

So, just for clarification; we know you can call C++ code from C# without too much trouble. We know Xenko does this with things like BulletPhysics. So, the big problem is not that Xenko couldn’t call something that you might have written in C++, but that you couldn’t write something that had to call Xenko APIs, right? So what stops you from writing a script in C# that would tell Xenko to go look something up in a C++ library?
I might be just confusing myself here.

Are you talking about doing something like?

public class MyCoolScript : SyncScript
{
    public string SomeProperty { get; set; }

    [DllImport("MyCool.dll")]
        public static extern int DoStuff(string c);

        public override void Update() 
        { 
             DoStuff("hello");
        }
}
1 Like

Right! Yeah, that makes sense. So you should be able to break up any project you have in C++ into components, write a bunch of scripts in C# that would call them at the appropriate time, and use Xenko as your rendering engine. You just have to have the “highest level” logic in the C# scripts that are controlling everything.

1 Like

I think you got it the other way around. There is no much issue calling native C++ code from C# (there are some but the point is it is already possible).

Calling C# code from C++ (which I think is the OP question) on the other hand brings its own kind of challenges. To be able to do scripting in C++ (unmanaged C++ that is) you will need this ability to call Xenko API.

Without access to all/most of the Xenko API from unmanaged C++ you would require so much bridging code to write scripts the way I had in my example. It would not be worth the effort just so you could code in C++. Not to mention marshaling all the data back and forth would probably be expensive.

I honestly can’t see any use for accessing unmanaged code from xenko other than for using existing libraries or performance reasons.

2 Likes