assetbundle scripts as dll... Help me please.

Jiraiya

Well-known member
Messages
481
Reactions
1,020
Points
93
Ok, so I made an assetbundle and it has a script that functions inside Unity. When I export it from Unity and load into VaM the script does not work.
The same script shoehorned into a VaM plugin gave no errors, but also didn't work. It seems for the more advanced features you need to make a dll which the assetbundle refers to. I know there are some in the hub already like this.

Could somebody please help me on how to achieve this? I have some great ideas for assets to put onto the hub but sadly can't do it until I get the more advanced unity features working.
 
You can't include code in the assetbundle no, that's my issue. But you can compile the script as a dll which you can simply put inside the var and have the asset reference it. This means the end user doesn't need to manually add a script to the asset to make it work.
That said, I need to check out what you just suggested in how you include the script. If that works it solves my issue and I don't need to go down the dll route anyway.
Thanks very much for the suggestion, I am now off to try it and see if it works.
 
Nope. I tried but it doesn't seem to execute the called script.
I put the line
SuperController.LogError("Test");

in both the main script that gets added in the init section, which gets called and displays in the VaM error log and in the unity Start() section in the script I am trying to get working, which did nothing.
It definitely gets "Loaded" because any errors in the called script bug out VaM and show in the error log when I induce them on purpose.
As is, it loads with no errors but does "nothing".

I can only assume that VaM isn't capable of doing what I am trying to do and I will have to go back to my idea of using a DLL instead to see if that works.
 
VaM automatically loads a DLL together with the AssetBundle, as long as it's in the same folder and has the same filename.

You can create such DLL with Unity Editor:
  1. Create your script(s) in Unity.
  2. If you haven't already move all script you want in the DLL into a folder (can also have subfolders)
  3. Right click in Project window: Create => Assembly Definition. Give it the same name as your AssetBundle will be named.
  4. Open your project solution in Visual Studio, e.g. via Assets => Open C# Project
  5. The Assembly Definition will appear as a "project" in your solution. Right click it and "Build"
  6. The DLL will appear (among a lot of other files) in Temp\bin\Debug of your Unity project. Could also be Temp\bin\Release, if you build in Release mode.
  7. Create a Prefab that uses one (or more) of your scripts
  8. Put the prefab into an AssetBundle as usual.
  9. Rename the AssetBundle to have the same name as the DLL, just with .assetbundle instead of .dll
  10. Copy both, the AssetBundle and the DLL into your VaM folder, like Custom\Assets\Somewhere...
  11. Add a CustomUnityAsset to your VaM scene and load the Prefab as usual. Scripts will be automatically loaded from the DLL.

These DLLs have the same restrictions as other VaM plugins. So you can't use Reflection, File IO stuff, etc.
What I'm not sure of is whether you can reference VaM code from within such a DLL that you build in Unity. E.g. whether you could have a MVRScript, etc. Might work when you add the correct references in the Assembly, or it might not.
 
" These DLLs have the same restrictions as other VaM plugins. So you can't use Reflection, File IO stuff, etc. "
Aaah. This might be my issue, I was actually trying to make a webcam.
In Unity I have a plane that I can scale and place inside a monitor that shows a hardware connected webcam on the PC in realtime. This works in Unity and I was trying to get it replicated in VaM so I can have a real webcam image appear on a screen inside VaM.

It sounds like this might just be a limitation of VaM that I can't get around. If the plugin doesn't work when applied as a script in VaM (without giving errors) I don't think compiling it as a DLL is going to magically make it work. Shame.

In case you were wondering, I have an HDMI capture device that appears as a normal webcam to windows. If I connect my cable box to this I can in theory display live TV on a virtual TV inside VaM, allowing me to watch movies/tv etc in whatever virtual environment I want as well as add company.
 
" These DLLs have the same restrictions as other VaM plugins. So you can't use Reflection, File IO stuff, etc. "
Aaah. This might be my issue, I was actually trying to make a webcam.
In Unity I have a plane that I can scale and place inside a monitor that shows a hardware connected webcam on the PC in realtime. This works in Unity and I was trying to get it replicated in VaM so I can have a real webcam image appear on a screen inside VaM.

It sounds like this might just be a limitation of VaM that I can't get around. If the plugin doesn't work when applied as a script in VaM (without giving errors) I don't think compiling it as a DLL is going to magically make it work. Shame.

In case you were wondering, I have an HDMI capture device that appears as a normal webcam to windows. If I connect my cable box to this I can in theory display live TV on a virtual TV inside VaM, allowing me to watch movies/tv etc in whatever virtual environment I want as well as add company.
As far as I know, you can use BepInEx to create plugins with fewer restrictions, but most likely you will not be able to place them in the hub.
 
As far as I know, you can use BepInEx to create plugins with fewer restrictions, but most likely you will not be able to place them in the hub.
Really? That sounds interesting. I can understand why the hub wouldn't host it, but should I get it working I will try and post publicly so people can try it.
 
There is also the IPA loader we used some centuries ago to make plugins before VaM supported plugins...and I eventually made a thing called "ScriptEngine"....which then finally convinced meshed to implement plugins properly :cool::ROFLMAO:

Making plugins with these methods should really be avoided, when possible, though. It's not safe.
 
Yeah, BepInEx looks extremely complicated and not at all easy for me to work out how to get my simple video texture working in VaM.
I will take a look at your ScriptEngine and see if that seems easier for me to understand.
I am honestly glad I came to VaM after scripts were part of it!
 
Back
Top Bottom