Unity3D AssetDatabase.LoadAssetAtPath() vs Resource.Load() - unity3d

My partner in game dev are looking at Unity. I dynamically loaded an asset using Resource.Load() and he used AssetDatabase.LoadAssetAtPath(). They both seem to work so which one should be used? Why have 2 different ways to dynamically load assets?

AssetDatabase.LoadAssetAtPath() vs Resource.Load() ...They both
seem to work so which one should be used?
None of them.
Your partner will end up with a game that he cannot build because he used AssetDatabase.LoadAssetAtPath(). The AssetDatabase.LoadAssetAtPath() function came from the UnityEditor namespace which is only used to make Editor plugins. It won't work outside the Editor and it won't even let you build your game at-all.
You using Resource.Load is fine but Resource.Load requires the use of the Resources folder which is known to cause slow down loading time of the game.
AssetBundles is the recommended way. You can put those files in the StreamingAssets folder then use the WWW or AssetBundle API to load it during run-time. You can learn more about how to use AssetBundles here

Related

Unity WebGL Build on BrightSign Player stuck loading

I want to run a Unity WebGL build on a BrightSign XT1144 player. (What should be possible in theory...)
Therefore I created an absolute simplistic Unity project (using v2020.2.6f1), not much more than displaying an image, and build it for WebGL. Then I published this build to the player using BrightAuthor:connected (using a HTML 5 Widget).
When I start the player the typical Unity WebGL loading screen appears and stops at approx. 90%.
Right now the build works fine on a local server and also online, but not on the BrightSign player.
I played around with the build/player settings in Unity but the behaviour of the build didn't change. (And of course I googled my fingertips bloody, but it's hard to find any kind of valid information...)
Does anyone already have experience with a scenario like this? Any help would be appreciated! :)
Things I tried:
Enabled Development Build
Disabled Compression
Disabled Data Caching
Disabled Engine Code Stripping
Updated BrightSign OS to 8.2.72
Finally I got it working!
This post in the Unity forum got me on the right track.
With the following publishing settings, my Unity (2020.3.2) WebGL build runs on the BrightSign XT1144 player. (BrightSignOS 8.x)
For anyone else that stumbles across this, got close with asj's solution but, at least when building with Unity 2021.3.1f1 and running on a Brightsign XD1033 on OS 8.4.14, I was getting the error
It seems your browser does not support running Unity WebGL content from file:// urls. Please upload it to an http server, or try a different browser.
Looks like Unity WebGL projects won't run locally anymore. Followed Brightsign's instructions here to get started with a NodeJS server on the Brightsign to host the WebGL. Moved everything created by the Unity build (index.html, Build, TemplateData, StreamingAssets) to a client folder within the node.js-starter-project-master folder. Modified the index.js express script to
const path = require('path');
var app = express();
app.use(express.static(path.join(__dirname, '/storage/sd')));
app.use(express.static(path.join(__dirname,'./client')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, './client/index.html'));
});
app.listen(9090, function() {
console.log('Example app listening on port 9090!');
});
Also had to update webpack.config.js so the client directory was copied to dist. Replaced the CopyWebpackPlugin section with
new CopyWebpackPlugin({
patterns: [{
from: './client',
to: 'client'
}]
})
From here, followed the instructions on the Brightsign GitHub to setup the NodeJS presentation. Added an HTML5 widget to the presentation with the Site Source URL at http://localhost:9090.
Under Presentation Settings>Support Content>Files I added the node-server.zip file created by webpack.
And it's still not doing what I need. Looks like it's technically working but the XD1033 isn't capable of playing my content (a relatively simple 2D game) smoothly. It will show the Unity player but has a hard time loading the game assets. But, if I access the url from a laptop connected to the Brightsign it loads just fine. A simpler game or a more powerful Brightsign might work better.
I might be able to get it working better with some optimization and tweaking but at the moment it's not worth my time and effort. I can just build for Windows and use a PC. Was just trying to use a Brightsign since we've found them easier to maintain long term. Might come back to it if I get bored and will update if I get it working better.

Access the OpenVR chaperone (Play area boundary box) without having SteamVR

I am trying to get access to the bounding box/Chaperone of my VR project without relying on SteamVR. I am trying to build a framework that works as native as possible to Unity.
In SteamVR one would write:
Valve.VR.OpenVR.Chaperone.ForceBoundsVisible(true);
// or
Valve.VR.OpenVR.Chaperone.ForceBoundsVisible(False);
My question is how can I do something similar to this with just the OpenVR package and not the SteamVR plugin.
thanks
You can use OpenVR SDK.
If you are using C#, there is a wrapper lacated at headers\openvr_api.cs.
At first you have to load library (openvr_api.dll) and init it like this:
var error = EVRInitError.None;
OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background)
Then simply use it the same way
OpenVR.Chaperone.ForceBoundsVisible(true);
You can also read chaperone_info.vrchap and steamvr.vrsettings from config folder of Steam. These json files contain information about all universes collision bounds.

javascript error airconsole generator and unity

Hi I am making a game on unity with airconsole and when I try to import the airconsole controls github repo to my unity project I get a lot of javascript errors, so I can't use the controller generator and it hinders me, A LOT.
Thanks in advance, you would save my skin.
Your HTML, CSS and JavaScript files, as well as all additional resources your controller will need (images etc.), need to be in Assets/WebGLTemplates/AirConsole so Unity will not try to compile them into C# or UnityScript.
Your controller HTML file itself can be somewhere else in the project, the file within Assets/WebGLTemplates/AirConsole will be updated automatically to match it as long as it is linked in the AirConsole Object in your scene.
If you add the plugin including example scenes into an empty project, you will see a working folder structure.
Edit/Update: in case you are getting errors along the lines of The type or namespace name 'ILGenerator' could not be found (or the same but with DynamicMethod) please see details on Reddit or StackOverflow.
Essentially: you have to set API Compatibility level o 4.x in your Player Settings for your selected platform.

Can both image target and object target be added one single database in unity vuforia?

I am developing an android app where I have to train my app to recognize two images and four objects.I created one single database where I added all the images and objects target in vuforia developer site and created the unity package. Now neither image nor object is getting recognized.
Probably the problem is the same for objects and images.
I think you should share some more info about what your doing as well as some meaningful code implementing it.
W/O that, I would suggest:
verify that the database and trackables are loaded and active # runtime
if so, see in console that the trackables are tracked by Vuforia
if so, verify the code enabling your augmentations
Please confirm whether have run trough these steps already and what results you got. I can share some code and further tips once the issue is a little but more specific.
Regards

Unity3d protect code

We have a code in a unity3d game that we wish to protect from decompilation(will be published in ios,android,webgl and unity plugin). How should we protect it? Should we write that part of code as unmanaged plugin(c++)?
It's not possible to release software that can't be reverse-engineered.
This is POSIBLE. Some packages have standart unity packager format. So.. If you use dynamic assets or if you use CodeContainers you need to protect your code.
So what you shoud do:
If you use dynamic assets packages: Make dll's from code or make one controller class.
If you use CodeConainers (JS) make main C# controller. After this you can extends classes or simply call methods.
PS: If you want to secure not code assets, you need make binary encoding. And when you load level or prefab you just decode this asset and use.
You could use obfuscation techniques, which allows you to protect your package from reverse engineering, but just from those, who is not VERY (i am talking about high-level reverse engineers, who could decompile your code and deal with ASM or could decompile your iOS/Android project) interested, in any case for Unity, iOS
You can obfuscate the your source code using the Remiix Obfuscator plugin in unity asset store.
It's free and easy to use and support many platform of build on unity(android, ios).