20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.74k stars 743 forks source link

Encapsulation of python within the game #100

Open StrangeCalibur opened 7 years ago

StrangeCalibur commented 7 years ago

Sorry this isn't an issue so much as it is an inquiry.

My plan is to make a programming/circuitry game in which the player can place micro controllers () and electrical components etc to solve challenges. Is there a way to encapsulate python within a single object using this? What I mean by that is every time the user places a "micro controller" or computing device, create a new instance that will run only with the inputs and outputs of that object?

rdeioris commented 7 years ago

Wow, i want to play this game asap :) You can already attach the PythonComponent or create blueprints from a PyActor or PyCharacter, but i suppose you want each object to have a separate python vm. Am i right ? In such a case i think a new component like PythonSubInterpreterComponent could be implemented exposing a whole new python subinterpreter for each object.

StrangeCalibur commented 7 years ago

Thanks for the reply! I think the subinterpreter idea is probably the best for my uses. I was looking at games such as shenzhen io and hardware engineering and thought to myself..... neither of these games really go far enough or are visually interesting in any way haha. Anyway my proof of concept levels are either going to be complete the drone and finish the course or getting something to work like a reactor or something, should be good fun!

rdeioris commented 7 years ago

Ok, i'll try working on it, it should be an easy task

StrangeCalibur commented 7 years ago

Thanks!

dkloving commented 7 years ago

Wow I had a similar idea and was thinking about exactly the same thing! +1 support for implementing this subinterpreter component.

Amorano commented 7 years ago

I am curious why you need an entire python instance when the answer to your inquiry is in the question: Is there a way to encapsulate python within a single object using this?

just use object(s)/classes/subclass objects. Unless there is some reason you need the full weight of a new python VM beyond just having an "initial state" for your black boxes? Effectively you want to make a Visual DAG, and DAGs are just nodes, and nodes are just objects.

unbit commented 7 years ago

@Amorano i suppose (but maybe i am wrong) that each player is free to load its code in the circuit so eventually a player can easily damage (even not voluntary) another one. @StrangeCalibur is it a real problem ? If not, well @Amorano is right, you only need the PythonComponent

Amorano commented 7 years ago

But people can just load that code (pesudo/python/whatever you decide) into said nodes for processing. If it is straight up PY code, python already provides faciltiies to run its code on the fly, just like any JIT'd lang.

I think you may be over-engineering the solution =D

EDIT: If you are worried about sandboxing, you can do all manner of things up front, like stripping imports other than those you allow, etc...

StrangeCalibur commented 7 years ago

Well lets see if I can explain it a bit better. Essentially there are 2 different things happening here, the player will be able to place electrical components on a board, such as resistors, capacitors, relays etc. in order to build or change a circuit in order to complete a challenge. The addition of micro controllers is where this gets a bit out of hand. Each micro controller placed on the board in each circuit needs to run its script separately and continue to do so when you exit that board and enter another one (Puzzles will for the most part have multiple stages, for example getting a cooling system online by controlling pumps etc, then the next part and next part. Maybe the last part would be to have everything turn on and off under certain conditions like the emergency stop button being pressed bla bla bla).

The other issue is making sure that python can only interact with the inputs and outputs of that micro-controller and nothing else. I was maybe under the mistaken impression that I could sandbox python in this way. I have been considering creating a small sudo language but I would really like to be able to allow players do some more complex things such as designing a flight controller for a drone or something.

StrangeCalibur commented 7 years ago

@Amorano you hit the nail on the head there, sandboxing is the real issue here.

Amorano commented 7 years ago

you can still "sandbox" the python easy enough. Just run their micro-controller code through a pre-processing step that strips out stuff you dont want them to use.

Also, the object itself can have as much or as little visibility to everything else since you control it. Now, given the "open" nature of python, the main problem would be where that "sandboxing" code lives.

To make it secure-ish, you'd be better off doing that in C++/UE side, as if it was a business logic layer in pyhon, it would be very easy to monkey with =D

StrangeCalibur commented 7 years ago

I will give it a go and see if I can find a way to sandbox it that way during the weekend, I am not too worried about the security right now though, at least until I have proved the concept however if python is completely limited to whatever inputs and outputs its fed as valid I don't think it could be much of an issue, its not like this is call of duty where cheating will get you anything haha. It would be like cheating in shenzhen io, yeah you can do it, but what have you achieved?