Does objects that have scripts attached to them will retain their parameters values if script is loaded using DLL? For example I have 3 objects with the same script but different parameters. How do I do this in VAM?
There is a way to load a DLL together with the asset bundle. However, so far I could not make it work for code that does have any references to VaM.You cannot create assetbundles with embedded c# scripts on them. This is a limitation of the assetbundle system.
Does objects that have scripts attached to them will retain their parameters values if script is loaded using DLL? For example I have 3 objects with the same script but different parameters. How do I do this in VAM?There is a way to load a DLL together with the asset bundle. However, so far I could not make it work for code that does have any references to VaM.
SecretRoom also uses VaM plugins to adjust things loaded by an CustomUnityAsset atom. Like changing material colors but also moving/rotating things.
Does objects that have scripts attached to them will retain their parameters values if script is loaded using DLL? For example I have 3 objects with the same script but different parameters. How do I do this in VAM?
Does objects that have scripts attached to them will retain their parameters values if script is loaded using DLL? For example I have 3 objects with the same script but different parameters. How do I do this in VAM?
// Get spawned prefab from CustomUnityAsset atom. Note that these are loaded asynchronously,
// this function returns null while the prefab is not yet there.
public static GameObject GetCustomUnityAsset(Atom atom, string prefabName)
{
Transform t = atom.transform.Find("reParentObject/object/rescaleObject/"+prefabName+"(Clone)");
if (t == null)
return null;
else
return t.gameObject;
}
Great! Thank you very much! Will go through it. I'm pretty able C# coder (its my job actually), but have little experience with codding for VAM.DLL is not the only solution... I haven't checked it because I can do mostly what I want with .cs files, so I can't tell you much about them.
But, for classical .cs scripts... I released a tutorial yesterday on the subject.
Great! Thanks! Will try.)Last time I tried this was over a year ago, but I think the limitations where this:
- You use VisualStudio to setup a project that references Unity libraries. Remove project references to any C# reflection code, VisualStudio likes to add those automatically when creating the project. Create a MonoBehaviour with your code and compile the whole thing as DLL.
- Put the DLL into your Unity project and build a prefab or scene that uses your MonoBehaviour. Just as you would normally do in Unity.
- Export the prefab or scene as AssetBundle (do NOT include the DLL)
- Place the AssetBundle somewhere in your Custom\Assets folder.
- Place the DLL in the same folder with the same name as the AssetBundle, just with *.dll extension.
- Use a CustomUnityAsset atom to load the AssetBundle, VaM will auto-detect the DLL and load it.
- You DLL can't use UnityEditor code, just UnityEngine. At least I could not figure out how. Usually you would build a second DLL with the editor-only code, but it messes up your script references stored in your prefab/scene. This rules out much code you would just take from the Unity AssetStore, like various special effects, etc.
- You can't reference VaM code. At least I could not figure out how.
Regarding finding a prefab spawned by a CustomUnityAsset from a plugin goes just like this:
You just have to be aware that it returns null while the AssetBundle is still loading. That's what the loop in @hazmhox tutorial is about. Make sure to store the result in a variable once you found it to avoid the constant polling.C#:// Get spawned prefab from CustomUnityAsset atom. Note that these are loaded asynchronously, // this function returns null while the prefab is not yet there. public static GameObject GetCustomUnityAsset(Atom atom, string prefabName) { Transform t = atom.transform.Find("reParentObject/object/rescaleObject/"+prefabName+"(Clone)"); if (t == null) return null; else return t.gameObject; }
So I have tried it. And I have a problem. VAM getting stuck at loading AssetBoundle, "Loading please wait" forever in CUA. If I uncheck load DLL then it loads, but without scripts. Here is my DLL code, it works in Unity.Last time I tried this was over a year ago, but I think the limitations where this:
- You use VisualStudio to setup a project that references Unity libraries. Remove project references to any C# reflection code, VisualStudio likes to add those automatically when creating the project. Create a MonoBehaviour with your code and compile the whole thing as DLL.
- Put the DLL into your Unity project and build a prefab or scene that uses your MonoBehaviour. Just as you would normally do in Unity.
- Export the prefab or scene as AssetBundle (do NOT include the DLL)
- Place the AssetBundle somewhere in your Custom\Assets folder.
- Place the DLL in the same folder with the same name as the AssetBundle, just with *.dll extension.
- Use a CustomUnityAsset atom to load the AssetBundle, VaM will auto-detect the DLL and load it.
- You DLL can't use UnityEditor code, just UnityEngine. At least I could not figure out how. Usually you would build a second DLL with the editor-only code, but it messes up your script references stored in your prefab/scene. This rules out much code you would just take from the Unity AssetStore, like various special effects, etc.
- You can't reference VaM code. At least I could not figure out how.
Regarding finding a prefab spawned by a CustomUnityAsset from a plugin goes just like this:
You just have to be aware that it returns null while the AssetBundle is still loading. That's what the loop in @hazmhox tutorial is about. Make sure to store the result in a variable once you found it to avoid the constant polling.C#:// Get spawned prefab from CustomUnityAsset atom. Note that these are loaded asynchronously, // this function returns null while the prefab is not yet there. public static GameObject GetCustomUnityAsset(Atom atom, string prefabName) { Transform t = atom.transform.Find("reParentObject/object/rescaleObject/"+prefabName+"(Clone)"); if (t == null) return null; else return t.gameObject; }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TestVamDLL
{
public class RotateAround : MonoBehaviour
{
public float speed;
void Update()
{
Rotate(speed);
}
public void Rotate(float speed)
{
transform.Rotate(Vector3.up, speed * Time.deltaTime);
}
}
}
Yeah, you are right, it was because of AssemblyInfo, forgot to check it. Thank you.)Random ideas:
- Check Unity error log. Not all errors are shown inside VaM. Go to %appdata%\..\LocalLow\MeshedVR\VaM\output_log.txt
- VisualStudio by default adds some AssemblyInfo.cs to the project. You need to remove that as VaM does not allow any references to Reflection stuff for security. (File IO is also forbidden)
- Since you mention to be a C# coder, you could use ILSpy decompiler to open VaM_Data\Managed\Assembly-CSharp.dll, it contains VaM's source code. Best "VaM documentation" available. Specifically I recommend to have a look at CustomUnityAssetLoader.SyncAssetUrl as it contains the code to load your DLL. https://github.com/icsharpcode/ILSpy/releases