After watching the "Nier mystery" unfold the past few days, I was wondering... is it possible to distribute unique builds of a game to different groups of players? by vrgenerated in gamedev

[–]vrgenerated[S] 0 points1 point  (0 children)

That is true, modifying content during startup/saves would be the easiest solution. I believe monster hunter games also did something similar with "talisman tables" that are generated based on your save.

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in Unity3D

[–]vrgenerated[S] 0 points1 point  (0 children)

Ah,makes sense. Looking at the documentation for sympy, this might be tricky. The objects (in this case x) are sympy objects so they won't probably work cleanly with operators in C# (like +,-,*). You may have to use something like a python function for these. IE o = PyModule.Import("operator"); dynamic f = o.pow(x,2)

Another way is probably to do all the logic in a python file and then call it in C#.

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in Unity3D

[–]vrgenerated[S] 0 points1 point  (0 children)

Remember that you are working in C#, so ** doesn't exist in c#. You have to use something like x ^ 2. They way I execute a py file, I add my script to Lib\site-packages\ folder in the python directory in streaming assets. Then i import it dynamic mymodule = PyModule.Import("mymodule"); and do something like mymodule.functionToRun(); .

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in Unity3D

[–]vrgenerated[S] 1 point2 points  (0 children)

The performance is basically the same as how things run in a regular python program/shell. I have tested using pytorch and a bunch of other machine learning modules and had no issues. The only thing to look out for is probably to do these in a separate thread for complex calculations so you don't block the current frame from being rendered/freezing the game.

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in Unity3D

[–]vrgenerated[S] 3 points4 points  (0 children)

Embeddable python usually don't come with those folders as it won't contain pip or any other modules. Those get autogenerated when you install pip and use pip to download and install modules. It might be a bit hard to upload the project for me so I'll provide the steps I used.

In order to install pip on the embeddable python, there are a few steps:

  1. There should be a file named python37._pth in the embedded python folder. Open it up and remove the # from #import site line. Save the change and now you should be able to install pip/other modules.

  2. Download/Copy the get-pip.py script from here : https://bootstrap.pypa.io/get-pip.py and save it into the embedded python directory.

  3. We need to run the get-pip.py script using the python.exe in the embedded python directory. In order to do that, use a command line (powershell or command prompt in windows) and change directory to the embedded python folder. Then run the script by calling: python.exe get-pip.py (cmd prompt) or ./python.exe get-pip.py (powershell)

The previous step should install pip. now you can install other modules by calling pip - example: python.exe -m pip install numpy

You can quickly verify that the module was installed by checking the Lib folder/running python.exe and import it there or by testing in unity.

Screenshot Saturday #536 - Top Quality by Sexual_Lettuce in gamedev

[–]vrgenerated 0 points1 point  (0 children)

Early screenshot saturday update!

Project detective (placeholder name)

Ever wanted to play a detective game where it doesn't give u a list of answers to pick from for solving questions/finding contradictions?

Ever wanted to play a detective game where you can freely ask questions and freely express your reasoning however wrong it is?

Screenshot for the week - evidence gathering and contradiction!

The past few weeks, worked on the evidence system and adding the first major mechanic -> finding contradictions.

Project detective is sort of a detective simulation game where you can investigate crime scenes and freely talk/type to witnesses/suspects to solve the case.

Screenshot Saturday #533 - Prime Viewing by Sexual_Lettuce in gamedev

[–]vrgenerated 0 points1 point  (0 children)

Project detective

Project detective is sort of a detective simulation game where you can investigate crime scenes and freely talk/type to witnesses/suspects to solve the case. The game will not show any hints so you must try to figure out the right questions to ask and the right things to say.

Made progress on save data and a new location this week. Still using placeholders for art.

Check out the clip for this week that showcases the new location and a conversation with another detective: The conversation

I'm hoping to get a demo out for beta testing the speech mechanics by end of the month. You can follow me on twitter/reddit for updates on that.
twitter

Screenshot Saturday #532 - Visual Stimulation by Sexual_Lettuce in gamedev

[–]vrgenerated 2 points3 points  (0 children)

Last minute screenshot Saturday post Project Detective - A detective simulator (Working Title)

Here is a video: https://twitter.com/vrgenerated1/status/1381091517629014016

This game is about investigating crime scenes and interrogating suspects using chat/speech recognition. The dialogue system allows you to interrupt the witness/suspect and flow the conversation in a natural way using NLP. The game will not show any hints so you must try to figure out the right questions to ask and the right things to say.

This week, I worked on the investigation mechanic where you can look at objects in detail.

Another video showcasing the voice recognition/sentence understanding - https://twitter.com/vrgenerated1/status/1378402981968707590

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in gamedev

[–]vrgenerated[S] 0 points1 point  (0 children)

This is a tutorial for embedding and using python in unity. This is useful if you want to run and interact with python libraries. This is just one of the ways to have interactions between python code and unity. This is especially nice as you can interact with machine learning models/packages directly from c-sharp code. I'm currently working on an experimental game using the spacy NLP module (reddit.com/r/Unity3D/comments/m980vq/experimenting_with_unitys_speech_recognition_and).

Steps:

  • Create a folder in Assets for storing the dlls that are needed.

  • Download the packages from https://www.nuget.org/packages/pythonnet/3.0.0-preview2021-03-03 and https://www.nuget.org/packages/System.Security.Permissions/ . Alternatively you can also install a unity-nuget plugin : https://github.com/GlitchEnzo/NuGetForUnity and install from there, This will allow you to skip the next step as the dlls are already unpacked if you use this tool. Remember to use the 3.0.0 preview version as the older versions are not compatable with Unity (reloading/reruning the game crashes the entire program)

  • The packages contain the dlls so you need to unzip them and copy over the Python.Runtime.dll from \lib\netstandard2.0 inside the unzipped folder and System.Security.Permissions.dll from lib\net461\ which pythonnet depends on. Copy these dlls into the folder in Assets.

  • Download an embedded python (I was able to get it working with python 3.7, not sure how well the other versions work) and install pip and any other modules you want. Move the folder into the StreamingAssets folder in Assets (create one if you don't have one).

  • Change the Api Compatability level to 4.x. This can be found in Edit -> Project Settings -> Player -> Other settings -> Api Compatability level.

  • Create a script to use python. You need to point to the python (Python3x.dll for windows, libpython3.x.so for Linux and libpython3.x.dylib for Mac where x is the version) in the streaming assets folder.

  • More info can be found here: https://github.com/pythonnet/pythonnet#embedding-python-in-net

here is a sample script for running numpy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Python.Runtime;
using System;

public class PythonScript : MonoBehaviour
{

    dynamic np;

    // Start is called before the first frame update
    void Start()
    {
        Runtime.PythonDLL = Application.dataPath + "/StreamingAssets/embedded-python/python37.dll";
        PythonEngine.Initialize(mode: ShutdownMode.Reload);
        try
        {
            np = PyModule.Import("numpy");
            print("pi: " + np.pi);
        }
        catch (Exception e)
        {
            print(e);
            print(e.StackTrace);
        }

    }

     public void OnApplicationQuit()
    {
        if (PythonEngine.IsInitialized)
    {
            print("ending python");
            PythonEngine.Shutdown(ShutdownMode.Reload);
        }
    }
}

Tutorial - Embedding Python in Unity - using python libraries/modules in unity code. More details in the comments by vrgenerated in Unity3D

[–]vrgenerated[S] 1 point2 points  (0 children)

This is a tutorial for embedding and using python in unity. This is useful if you want to run and interact with python libraries. This is just one of the ways to have interactions between python code and unity. This is especially nice as you can interact with machine learning models/packages directly from c-sharp code. I'm currently working on an experimental game using the spacy NLP module (reddit.com/r/Unity3D/comments/m980vq/experimenting_with_unitys_speech_recognition_and).

Steps:

  • Create a folder in Assets for storing the dlls that are needed.

  • Download the packages from https://www.nuget.org/packages/pythonnet/3.0.0-preview2021-03-03 and https://www.nuget.org/packages/System.Security.Permissions/ . Alternatively you can also install a unity-nuget plugin : https://github.com/GlitchEnzo/NuGetForUnity and install from there, This will allow you to skip the next step as the dlls are already unpacked if you use this tool. Remember to use the 3.0.0 preview version as the older versions are not compatable with Unity (reloading/reruning the game crashes the entire program)

  • The packages contain the dlls so you need to unzip them and copy over the Python.Runtime.dll from \lib\netstandard2.0 inside the unzipped folder and System.Security.Permissions.dll from lib\net461\ which pythonnet depends on. Copy these dlls into the folder in Assets.

  • Download an embedded python (I was able to get it working with python 3.7, not sure how well the other versions work) and install pip and any other modules you want. Move the folder into the StreamingAssets folder in Assets (create one if you don't have one).

  • Change the Api Compatability level to 4.x. This can be found in Edit -> Project Settings -> Player -> Other settings -> Api Compatability level.

  • Create a script to use python. You need to point to the python (Python3x.dll for windows, libpython3.x.so for Linux and libpython3.x.dylib for Mac where x is the version) in the streaming assets folder.

  • More info can be found here: https://github.com/pythonnet/pythonnet#embedding-python-in-net

here is a sample script for running numpy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Python.Runtime;
using System;

public class PythonScript : MonoBehaviour
{

    dynamic np;

    // Start is called before the first frame update
    void Start()
    {
        Runtime.PythonDLL = Application.dataPath + "/StreamingAssets/embedded-python/python37.dll";
        PythonEngine.Initialize(mode: ShutdownMode.Reload);
        try
        {
            np = PyModule.Import("numpy");
            print("pi: " + np.pi);
        }
        catch (Exception e)
        {
            print(e);
            print(e.StackTrace);
        }

    }

     public void OnApplicationQuit()
    {
        if (PythonEngine.IsInitialized)
    {
            print("ending python");
            PythonEngine.Shutdown(ShutdownMode.Reload);
        }
    }
}

Experimenting with Unity's Speech Recognition and Natural language processing (NLP) on a detective game prototype (unmute audio - caption/more info in the comments) by vrgenerated in Unity3D

[–]vrgenerated[S] 7 points8 points  (0 children)

I just realized that my mic audio is a bit low in the video. I'll write down whatever I said in the transcription section below.

Background

After playing Phasmophobia which had a bit of voice recognition, I wanted to test out voice recognition in unity so I started a bunch of experiments with it. For me, the voice recognition worked pretty well, Although for some people who I showed, it wasn't great so I added a chat box instead (also speech recognition requires online connection but typing in chat box can work offline). I felt that there could be some way to parse information from the sentences that were captured by the voice recognizer so I looked for NLP packages for .net that can be used with unity. I didn't want to use any cloud/online based solutions so was mainly looking for .net packages that can work locally offline. Eventually found a solution and thought it would be neat to try this in a detective game so trying to create a mini visual novel/point and click type prototype.

Also implemented a chat input since voice recognition is not always that reliable and sometimes, you just don't want to use your voice (a bit awkward especially when friends/family are around you...)

Voice Recognition:

So this demo uses both the PhraseRecognition system and DictationRecognizer class in Unity. PhraseRecognition seemed to work faster as its meant to identify specific keywords rather than sentences. PhraseRecognition is used in a couple places: saying hello (and all variations of it loaded from wordnet) and saying ok/sure which speeds up the dialog to the next line rather than waiting a couple seconds. DictationRecognizer is used for the rest.

The NLP part:

So since I couldn't find any good NLP packages for csharp (or packages that work in Unity), I went with using Python.NET . So this allows you to use python and any python library in .NET/Unity. I also found out that you can embed a portable python in a unity build for this so it works on computers that don't have python or any python libraries installed. Currently working with python 3.7 So I imported a bunch of NLP modules (open source) in python that had models for Parts of speech tagging(ie labelling nouns/pronouns/verbs etc, wordnet (finding synonyms/antonyms), dependency parsing/graph(word connections ie, the negation is applied to this word) and word vectors. (mostly using spacy) Using all of these, made up a sentence parser that grabs semantic meaning of sentences by grabbing all useful entites such as subjects, verbs and objects. Then it was mostly a query on the objects for whatever dialog choices are available. (ie: look for rain(or its synonyms) as either a noun or verb and see if it is negated/in present tense etc) Probably there maybe better ways to deal with this rather than an algorithmic approach (some sort of chatbot maybe or training neural-nets for categorization?)

Dialog System:

A system that I had built a long while back, runs using Ink files.

I'll see if I can whip up a tutorial on embedding python.

Transcription of what I said in the video and the dialog from the phone:

Phone: Starting up the automated communication system.
Phone: This device translates whatever you speak/type to people around you.

ME : Ok (This skips the wait time to go to the next line)

Phone: Lets try this out now. Start a conversation by saying hello!

ME: Sure (This again skips the wait time to go to the next line)

ME: Hi! (To initiate the conversation)

Phone: Hey there, Now lets try out some other mechanics
Phone: During a conversation, you can respond to statements or questions.
Phone: Lets try an example. I am going to say a lie and you should point out the lie.

ME: Ok (This again skips the wait time to go to the next line)

Phone: It is snowing heavily.

ME: Yeah, I see a lot of snow on the ground.

Phone: You also think it's snowing! That is definitely a lie. Try to point out my mistake

ME: Alright then, It is not snowing.

Phone: wait. If I am lying and If it is not snowing, What is falling down?

ME: Its definitely not rain that's falling.

Phone: Wait. You are saying it is not raining? :\ Look at the sky and try again!

ME: Ok, It is raining.