Load an asset from outside a 'resources' folder - unity3d

I'd like to load "dynamic" assets (in particular, FBX files) that are located outside of a "Resources" folder so that the user can add/remove/modify files with no need to re-build the project.
To make those files easily accessible for the user in different kinds of devices (target platforms are desktop/android/ios), it seems reasonable to use either Application.persistentDataPath or Application.streamingAssetsPath.
Now the problem is: How do I load them (as proper Unity objects) ?
This obviously can't be done via Resources.Load() as they are outside a "Resources" folder.
Using WWW, retrieving the files should be easy and it could actually work for some types of files (e.g. textures, see http://docs.unity3d.com/ScriptReference/WWW-texture.html) but I cannot see a way to load something else.
The idea is that I'd like to be able to use those loaded objects like so:
(GameObject) Instantiate(loadedObject, new Vector3(0, 0, 0), Quaternion.identity);
I would really appreciate your help (preferrably with a solution that does not require a "pro license").

I know two options that you can try to use in this case:
Build an asset bundle for each dynamic asset you want to load, but this seems not really what you desire, because the user still have to use Unity3d to generate the asset bundle.
Use an custom 3d model loader, like described in this post, seems the best fit for your case.

Related

Unity UniWebView how to show images from my Resources (Assets)

i have a few quick questions:
background:
i want to display a in-code generated html with UniWebView in my game. Mostly works nicely until i try to display local images (from my unity-resources)
the images are in my "Resources" folder (and used elsewhere in the project also)
my goal to support Android/iOS/Windows environments with the game
Q1: can i display images from "Resources"? this would be the best if i could
Q2: do i need to move all my assets into the "StreamingAssets" folder and access from there? if so, can "StreamingAssets" folder be under "Resources" folder? like this: "Resources/StreamingAssets"? If so please confirm that i can use them as unity resource for unity components AND also streamable assets for UniWebView in the same time?
thanks!
daniel

Including non-standard resources in Unity HoloLens app

I'm building an app that must visualize a large point cloud on HoloLens 1st gen. As performance is an issue wit large clouds, I'm using Potree, an octree that takes care that only a preset number of points from the cloud are rendered.
The solution works in the editor, but, you guessed it, not when deployed on HL.
The point cloud in the Potree format is a set of couple of .json and hundreds of .bin files stored in hundreds of subfolders following the octree structure, all of that stored within a single folder, and the path to this folder is accessed by the renderer at runtime. However, I don't know how to include this folder in the HL app. Using Resources doesn't work as it's not really a standard resource. I've seen Asset Bundle suggested elsewhere, but according to this post asset bundling doesn't work on HL.
Is there a way to simply put this complex file structure in an accessible directory on HoloLens?
I feel completely stuck here and any help would be much appreciated.
Some of the things I've tried:
Keijiro Pcx doesn't work here. If rendered as single pixels, points cannot be seen in AR, and if rendered as meshes, the performance is abysmal (which led me to a conclusion octree structure should be used)
the solution here shows how to load one .xml file, but I have hundreds of files so I don't think it would work for me
similarly, this post deals with one .obj file
Unity 2019.4
HoloLens 1st gen
For anyone stumbling upon this - I ended up using Unity StreamingAssets and accessing the folder with Application.streamingAssetsPath - works beautifully!
Using pcx needs to be adjusted to binocular rendering in publishing settings. Please uncheck "Enable Depth Buffer Sharing" in XR Settings, and change "Single Pass" to "Multi Pass", as shown in the figure.enter image description here

Can we overlay the file to our custom path

Can we overlay the file to our custom path or we have to overlay the file to exact folder structure location as in libs?
For example, I want to overlay the constants.js (/libs/cq/ui/widgets/source/constants.js) file, in this adobe recommended Copy this file to /apps/cq/ui/widgets/source/constants.js for overlaying, but in my project that folder structure is not there, so I have copied to the custom path in apps folder and tested the changes and overlaying is working fine.
The file needs to have the same path as the one in libs except for replacing 'libs' with 'apps'. It does not work with custom paths*. If the project does not already have the structure, you can always create it. Don't forget to update the META-INF/Vault/filter.xml file to register the new path with projects package definition.
*Technically you can change the configs to add new searchpaths. But do remember that you might have to share the AEM instance with different tenants and sticking to the usual conventions goes a long way in having a predictable setup. I honestly don't see a reason to do this, it is already an acceptable practice to overlay under '/apps'. The filters on package provide enough flexibility to get along with other tenants while modifying similar areas.
I think you want to create the overlay in your custom project under /apps. If my assumption is correct, then you can certainly do it.
Taking your example in consideration, /libs/cq/ui/widgets/source/constants.js can be overlayed to /apps/<your-project>/cq/ui/widgets/source/constants.js by adding an entry in the Apache Sling Resource Resolver Factory configuration.
See this answer for the detailed steps. I hope this helps.

Errors loading scripts on prefabs from asset bundles

I'm currently trying to set up my project to allow users to download mini games post release. Todo this I am trying to use asset bundles to facilitate this, one containing the new games scene and one containing the assets and DLLs for the scripts required. The problem I am having is that when I load the scene or a prefab from the bundle all the attached scripts are still there but a warning says "the associated script can not be loaded. please fix any compile errors and assign a valid script". Is there something obvious that I am missing or do asset bundles not work this way and I'm going to have to rebuild my scene on load?
You can't have the scripts in the asset bundles assigned as references from GameObjects like you normally would. You can only access scripts from asset bundles by loading them with reflection. Then you can programmatically attach them to GameObjects, etc. from there (for example, load the assembly, find your Type, then use AddComponent() on a GameObject with your new loaded type).
See http://docs.unity3d.com/Manual/scriptsinassetbundles.html.
But even if you were to overcome these hurdles, it won't work on Windows Phone and it's against the terms of service of Apple's store, so ...

Creating walkthrough dynamically in unity3d

I want to using the Unity3d framework for a project in which I have create a walkthrough. But the client want it to be dynamic.
We would be getting the final fbx file from 3DMax which when added to a particular folder a walkthrough should be created automatically. I went through the help files on Unity3D site but did not find any documentation as to how use the Unity3D framework programmatically.
Can anyone please let me know how can it be done? Even if link is provided for the resource it would help us.
Unity 3D has a built in way to load models at runtime, but this should be done using a Resources folder (Resources.Load()) or using a Asset Bundles (AssetBundle.Load()) as described here: http://docs.unity3d.com/Documentation/Manual/LoadingResourcesatRuntime.html
These two methods are performed inside the Unity editor and your need is load any arbitrary 3D model file at runtime, for this case you will need a plugin. The only one that I know is ObjReader.