Search Unity

Integrating Artificial Intelligence in Unity

Discussion in 'General Discussion' started by vedantgirkar32, Sep 4, 2020.

  1. vedantgirkar32

    vedantgirkar32

    Joined:
    May 28, 2020
    Posts:
    10
    Im planning to make a stock market prediction game. In this I have already made an Artificial Intelligence model ( RNN-LSTM ) to predict the further stocks for the company. And now want to create an 2D UI for it.

    So is it possible to integrate a pre-trained Artificial Intelligence model in unity and create a game around it?
    If yes could you'll elaborate the steps to proceed with it.
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    What language does your model require? You should look into integrating whatever that is with C#. Unity itself shouldn't be a problem.
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    You would need to find C# bindings for the library you're using, or write them yourself. And that's pretty much it.

    Also, if you JUST want a 2d UI, it may be easier to use an ui framework for that instead of Unity.

    By the way.... I tried to do something similar (stock prediction) in the past, results weren't good.
     
  4. vedantgirkar32

    vedantgirkar32

    Joined:
    May 28, 2020
    Posts:
    10
    The Model that I have made in python.
    Is there any particular package or method to integrate keras or tensor flow models in unity
    And also how to approach Artificial Intelligence in unity.
     
    Last edited: Sep 5, 2020
  5. vedantgirkar32

    vedantgirkar32

    Joined:
    May 28, 2020
    Posts:
    10
    Hey thanks for the reply
    I'm a beginner in game development especially integrating an Artificial Intelligence model into it.
    Can you tell me what were the problems you faced while doing your stock market predictions project cause it would really help.
     
  6. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    As I said before, you don't need to worry about importing things into Unity, but into C#. And that's not really the topic of this forum (and there's plenty about it online).

    https://www.google.com/search?q=integrate+keras+model+into+c#

    Integrating that into Unity is as simple as assigning your model's output to a variable you can access from any Unity script.
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Does it have to be AI?
    What you could do, is work other way round (smoke and mirrors).
    Make a prediction into future, then generate stock change, along prediction over the time, with fluctuation and relevant errors.
    So your prediction is a pilot, to generate actual stock changes.

    Otherwise, you may want to look something like MPC (Model predictive controller), Unity ML, using python (but not real time training, as far I am aware), Or even Neural Networks, of which multiple C# codes you have available on github.
     
  8. ChazBass

    ChazBass

    Joined:
    Jul 14, 2013
    Posts:
    153
    You certainly could do so by creating some bindings to run the model from C#, or compile it to C and call it from C#, but why do so? Lot of great GUI libraries for Python (Atlas, Pyjamas, etc.). Unity would be a heavy solution to that problem.

    And if you are asking because you are thinking about using Unity for cross platform mobile development, there are lots of discussions on this here already. The long and the short of it is: Yes, you can. But it would not give the best experience on mobile due to download size, application start up time, and the battery consumption a game engine is going to incur versus just using something like React Native, Xamarin etc. React Native can execute C and Python can be trivially compiled to C.
     
  9. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    He said game. Not a React stock market widget. Unity Barracuda https://docs.unity3d.com/Packages/com.unity.barracuda@3.0/manual/index.html is lightweight, runs fine on Android and iOS too. and can run ONNX models which have a github repo https://github.com/onnx/models and can be found on huggingface https://huggingface.co/models. MathNet https://github.com/mathnet will give you the maths you need for predictive models . Any python can be replicated almost line for line with SciSharp https://scisharp.github.io/SciSharp/ .
     
    Last edited: Dec 15, 2022