# Unity/C# Accessing Data Files to pass to a DLL/API

**URL:** <https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366>\
**Category:** Game Tech\
**Created:** [September 14, 2017, 2:14am UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366 "2017-09-14T02:14:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chief\_ed](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chief_ed/32/71076_2.png) [@chief\_ed](https://forums.kodeco.com/u/chief_ed)\
**Post date:** [September 14, 2017, 2:14am UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/1 "2017-09-14T02:14:39Z")

</div>

Salutations!  
In my Unity Project, i have added a “plugin” DLL.  
This library requires data files to be fed in to it.

Can someone show me how to do this in Unity/C#?

I have seen it done in straight C# with this library, but there are some idiosyncrasies in Unity/C#,

ALSO: I there any precedent of this architecture working on mobile devices?

Thank you for considering my problem and let me know if you need more information!

Cheers!  
Chief\_Ed!

---

<div class="post-metadata">

**Author:** ![blackdragonbe](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/blackdragonbe/32/109865_2.png) [@blackdragonbe](https://forums.kodeco.com/u/blackdragonbe)\
**Post date:** [September 14, 2017, 9:11pm UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/2 "2017-09-14T21:11:46Z")

</div>

@chief_ed  
Hi there!

Have you added the DLL to the “Plugins” folder?  
If so, is it a .NET library? What version of .NET was it compiled with?  
To answer your second question: yes, it will probably work on mobile if it’s not platform specific.

If you can give some more details about the plugin/library and how the documentation says it should be used I can offer more help.

Cheers!  
Eric

---

<div class="post-metadata">

**Author:** ![chief\_ed](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chief_ed/32/71076_2.png) [@chief\_ed](https://forums.kodeco.com/u/chief_ed)\
**Post date:** [September 15, 2017, 3:10am UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/3 "2017-09-15T03:10:00Z")

</div>

Hi Eric,  
I have created a “Plugins” folder and I added the DLLs there (for the sake of good file management, I am told). Unity recognizes the DLL, which is written in .NET version 2, I believe. The Inspector seems to recognize the library, and shows a screen displaying the platform options.

There is no documentation for what I want to do with it, but I do have a snipit of code explaining how to access the library in C# per say. I will include that below.

The library is for an old product called CLIPS (C Language Integrated Production System)  
CLIPS requires files to feed it information to run.

I need help figuring out how to get Unity to route these files into Unity/C# so I can feed them to CLIPS…

Here is the code I was shown that works with C# stand-alone. As you can see, it uses the disk structure to feed the data file into C#. I need a different way to do this fr the Unity project:

```auto
using System;

namespace GetMarriedOrStaySingle_AsCSharpApp
{
   class Program
   {
       static void Main(string[] args)
       {
           CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
           theEnv.Load(@"..\..\..\SocratesKnowledgeBase.clp");
           theEnv.Reset();
           theEnv.Run(-1);
       }
   }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can you help me?
-Chief_Ed
```

---

<div class="post-metadata">

**Author:** ![blackdragonbe](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/blackdragonbe/32/109865_2.png) [@blackdragonbe](https://forums.kodeco.com/u/blackdragonbe)\
**Post date:** [September 20, 2017, 7:42pm UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/4 "2017-09-20T19:42:50Z")

</div>

@chief_ed  
Sorry for the late reply,

If I understand correctly, what you’re looking for is a way to run that code on start-up like the Main method would do in a regular C# project?

Create a new C# script anywhere in your Assets folder (preferably in a Scripts folder) and name it CLIPSLoader. (see this tutorial if you’re confused: [https://www.raywenderlich.com/127672/introduction-unity-scripting](https://www.raywenderlich.com/127672/introduction-unity-scripting))

Open it up in your C# IDE and you’ll see a `Start()` and an `Update()` method.  
Start() will run once when the GameObject the script is attached to is loaded in the scene, so that’s where you want to put your code.

For example:

```
void Start()
{
    CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
    theEnv.Load(@"..\..\..\SocratesKnowledgeBase.clp");
    theEnv.Reset();
    theEnv.Run(-1);
}

```

You may need to add a reference to the CLIPS library by adding a `using` statement at the top.

Now add a new empty GameObject to the scene and drag the script on top of it (or select the GameObject and add it in the Inspector as a component).  
Now run the scene and the code will be executed.

Be sure to check out our tutorials to find your away around the editor.

Hope this helps!  
Cheers

---

<div class="post-metadata">

**Author:** ![chief\_ed](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chief_ed/32/71076_2.png) [@chief\_ed](https://forums.kodeco.com/u/chief_ed)\
**Post date:** [September 20, 2017, 10:18pm UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/5 "2017-09-20T22:18:05Z")

</div>

Hi Eric,  
Thank you for taking the time to reply.

I do not think I was clear in my original message. I apologize for the confusion.

Here is the actual code in my C# script:

For illustration purposes, my C# script is as follows:

```auto
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CLIPSNet;

namespace TakeAByteSolutions.LISP.Unity 
{
public class GetCLIPS : MonoBehaviour 
  {
    // Use this for initialization
    void Start () {        
// Debug.Log("Getting Started");
        }

    // Try to open CLIPS from Unity
    void OnDisable()
    {
            Debug.Log ("Disabled toolbox..."); //OK, you got here.
        CLIPSNet.Environment theEnv = new CLIPSNet.Environment();
// theEnv.Load("basics01POC.clp");
// theEnv.Reset();
// theEnv.Run(-1);

            Debug.Log("Step by step, row by row...");
 }
        void OnEnable()
        {
            Debug.Log ("Enabled toolbox...");
            //
        }
}
}

```

As you know, since this is in Unity, there isd no “Main” class. Also, for testing purposes,  
I have this code attached to the “Disable” event of an object in the project called “Toolbox”.

What I now need is someone who has access to the CLIPS source code and can re-compile an asset that I need; the **CLIPSLib.dll** file.

Is this something you can do? If not my search continues!

Thank you for your attempts to help me. The effort is appreciated!

Cheers,  
Chief-Ed

---

<div class="post-metadata">

**Author:** ![blackdragonbe](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/blackdragonbe/32/109865_2.png) [@blackdragonbe](https://forums.kodeco.com/u/blackdragonbe)\
**Post date:** [September 21, 2017, 5:21pm UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/6 "2017-09-21T17:21:40Z")

</div>

Hi Ed,

I’m afraid I’m not familiar with CLIPS so I can’t help out there.  
Good luck on your search!

Cheers!  
Eric

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [February 27, 2018, 6:14pm UTC](https://forums.kodeco.com/t/unity-c-accessing-data-files-to-pass-to-a-dll-api/34366/7 "2018-02-27T18:14:41Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
