Loading UI Toolkit assetbundle from Mod - c#

I have written a mod for a video game that has a basic level of mod support, and provides a loader and access to game data etc. Currently the UI for the mod is using the IMGUI and I want to get rid of it.
I've been trying to write a proper UI in Unity, building an assetbundle but am struggling on getting my mod to actually load it.
As a POC I created the exact UI from the manual below, and the C# Script to build the bundle. This works, the manifest file lists my asset inside of the bundle.
https://docs.unity3d.com/Manual/UIE-HowTo-CreateRuntimeUI.html
https://docs.unity3d.com/540/Documentation/Manual/BuildingAssetBundles.html
Inside of the game when I try and load this asset from my mod at the most basic level I'm getting an error
Unable to read header from archive file: C:/Test/CustomAsset/customui.assets
Failed to read data for the AssetBundle
Script used to load test:
var bundleLoadRequest = AssetBundle.LoadFromFile(
Path.Combine("C:\\Test\\CustomAsset", "customui.assets"));
Log(bundleLoadRequest.GetAllAssetNames().ToString());
I know this path is valid because if I type an invalid path I get a different error "unable to locate asset" or something to that effect. If someone could please assist in pointing me in the right direction

Asset Bundles generally only work for the Unity version they are built with. Is it possible there is a mismatch between your editor version and the version the game you are modding was created with?
Sadly there is no Version check at the beginning that will let you know and they just won’t work.

Related

The type or namespace name "..." could not be found - Unity Vuforia

I am pretty new to Unity and Vuforia. I am trying to do solve this following problem. I have a script file that I am using for 2 different Image targets. Only 1 script should be running at a time. So i opened "DefaultObserverEventHandler.cs" to handle tracking events. I want to disable the script on that particular Image target when the tracking is lost. But when i try to get a reference on the script "QuizzBehaviour" i get an error. "QuizzBehaviour" is located in my Assets folder. Thanks in advance.
Ok, I fixed it. I made my own "DefaultObserverEventHandler.cs" script and placed it in the same folder where my "QuizzBehaviour.cs" script is.
"Find" will search through objects in scene not in your folders.However, at all costs you should avoid searching for objects by typing their name manually.In your case, the matter is quite simple. You can either add a script to an object and then use the get component command, or you can make an abstract class and refer to it.

Problems in Unity

This is a copy of a question from StackOverflow in Russian. Translated by DeepL
In Unity, even in a newly created project, there are a number of bugs:
Socket: bind failed, error: An attempt was made to access a socket
using a method prohibited by permissions. (10013)
Unable to join player connection multicast group.
Assembly for Assembly Definition File
'Packages/com.unity.textmeshpro/Tests/Runtime/Unity.TextMeshPro.Tests.asmdef'
will not be compiled, because it has no scripts associated with it.
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline
(UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget)
The latter only at the first launch of the created project.
Unity version - 2019.4.26f1 (64-bit)
What is this and how to fix it?
P.S. The answers I have found do not help.
TextMeshPro is a preview asset that you might want to delete(unless you're actively using it, which I doubt since this ran on initial startup).

How to programmatically clear application data in unity

I`ve been developing android game in unity3d. My app uses a lot of storage memory so I wanna clean it up after close (user presses the quit button and all cached memory gonna reset). It should work like the "Force Stop" on device. I wrote the method:
private void deleteData() {
String packageName = getApplicationContext().getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec(""+packageName);
I have following errors in unity editor:
The name `getApplicationContext' does not exist in the current context.
The type or namespace name `Runtime' could not be found. Are you missing an assembly reference?
I should import "Runtime" but I couldn`t find how to exactly do it in c# script. Is it possible to implement Android sdk methods in c# scripts? Thanks for help.
No need to make you proper module to do that, you can just delete cache using Caching.ClearCache(); inside Unity, it will delete all the cache created by the application. Also if you want to delete just the player preferences you can use PlayerPrefs.DeleteAll();

Programmatically import Asset in Hierarchy Unity

For a schoolproject we're working on a project for loading BIM-models into unity. We are working with .ifc files, which we convert to .dae for the time being. We created a script for importing the files using EditorUtility.OpenFilePanel. We are using IFCOpenshell's IFCConvert (a command line utility).
This goes well, and the Asset shows up in the Assets folder. The only thing left to do now, is importing the asset runtime into the Hierarchy *without dragging it into the scene or hierarchy *.
We've tried to use a WWW stream to get the file and assign AssetBundles to it and a few other methods, but no luck yet.
"The only thing left to do now, is importing the asset runtime into the Hierarchy"
Unless I misunderstand you: for items in "Project" (ie, your assets), if you want to put them in the current scene .. drag them in to the scene.
(ie, drag them either in to the Heirarchy panel or just literally in to the middle of the scene Editor.)
Are you saying you're trying to automate this ?? (I don't really see how you could - any button you added would be more difficult than .. just dragging them in.)
If you are simply asking how to load (at runtime) Resources, just look in to
Resources.LoadAll()
You'll learn that you have to keep the items in a "Resources/" folder and so on. It is well documented. There are 1000s of QA on the topic. Example code fragment
ra = Resources.LoadAll("VO/", typeof(AudioClip) ).Cast<AudioClip>().ToArray();
It is beyond the scope of a QA site to provide a tutorial on "Resources" but you can instantly find this on Unity3d.com.
Note that if, very simply, you just want to use a particular model in the build. Do nothing more than, drag it to the scene and place it where you want. Then in code just
public GameObject yourBuilding;
and use inspector-dragging to link that variable as you wish. Then you can use that variable as you wish. Note that for large complicated models, often you will go ahead and just have different inspector variables for the different parts, rather than even bothering to drill-down. (So, you might have "hospital", "eastWing" "corridor" .. etc. and just go ahead and "inspector-drag" those.)

Soundeffects not working. Could not load ... asset

So I'm trying to implement soundeffects whenever I click on an item. I've added a .wav sound to my Content folder.
Then I typed the following code in the Game1 class constructor:
SoundEffect soundEffect;
After that I wrote the following code in the Initialize function:
soundEffect = Content.Load<SoundEffect>("Laser_Shoot25.xnb");
Finally, I wrote the following code in my clickFunction:
soundEffect.Play();
When I tried running it, it gave me the following error.
Could not load nameOfSoundFile asset.
I've looked on Google to see if someone else had this same problem, but none of those solutions seem to work for me.
Does anyone know what else I'm supposed to do to make this work?
First thing that comes to mind is the possibility of you loading your assets before the Content object gets initialized. Please post the relevant code where you load your asset to know if this is the case (usually the initialize and LoadContent methods of your Game1 class).
The other possibility is the asset file format.
I'm not up to date with Monogame as I stopped using it with version 3.2, but if things remain the same on this aspect; then for working with sounds and spritefonts you need to add the asset as an exported xnb file, created by using the actual XNA content pipeline.
I have a blog post that explains exactly how to do all of this, which can be found here.
First, you need to install XNA on your machine (in the same post, it explains how to do it if you have Windows 8 and/or Visual Studio 2012/2013).
Then, just follow the steps detailed on the post:
So, once we have this, let’s create a new Windows Game project (it has
to be a game and not only a Content project as we will need to access
the game output directory).
After having this done, we can add our sound effects/instances to the
Content project by right clicking, selecting “Add existing item” and
choosing it in the folder explorer.
Before continuing, make sure you set the properties of the sound as
desired (in my case, I’ll be using a SoundEffect so I need to specify
it in the Content Processor field):
All that remains is to add the xnb file to the Content folder of your
Monogame project.

Categories