Skip to content

Thanks for this amazing plugin. #1

Locked Answered by exodrifter
nasir41 asked this question in Q&A
Discussion options

You must be logged in to vote

There is no simple way to "import" your python code to Unity. I'm not really sure how to do it myself, but I can suggest reading the IronPython documentation on Accessing Python code from other .NET code for starters.

Alternatively, you can wrap every function you want to access and then invoke them from C#. From this stackoverflow example:

var pySrc =
@"def CalcAdd(Numb1, Numb2):
    return Numb1 + Numb2";

// host python and execute script
var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
engine.Execute(pySrc, scope);

// get function and dynamically invoke
var calcAdd = scope.GetVariable("CalcAdd");
var result = calcAdd(34, 8); // returns 42 (Int3…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by exodrifter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1 on December 21, 2020 15:18.