Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Loading assets dynamically in a VR-project (Rift) - is this the correct way and possible?

Discussion in 'Scripting' started by Yeehaw, Aug 17, 2015.

  1. Yeehaw

    Yeehaw

    Joined:
    Aug 15, 2015
    Posts:
    2
    Hello everyone,

    I would like to run down my use case to check if it is possible the way I would like to implement it.

    I have a client VR-application running on an Oculus Rift DK2. This application is supposed to dynamically download assets from a remote server on-demand. The users can choose the items they want to be displayed in their virtual world and they will be fetched after being chosen. Items are in .obj format, which are importable into a Unity project without problems (tested).

    As far as I understand, I need a few things for this:

    - A server running scripts to create asset bundles from each .obj file and its materials, textures, etc.
    - A WWW connection to fetch these asset bundles upon request in my client app, and a way to create the actual models from these assets

    What are the steps necessary for this?
    Again, as far as I understand I need scripts on the server-side packing the files into an asset bundle, using something like this (C#):

    Code (CSharp):
    1. static void BuildAssets() {
    2.      AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
    3.      string[] assets = new string[2];
    4.      assets[0] = "object";
    5.      assets[1] = "material";
    6.      buildMap[0].assetBundleName = "objectBundle";
    7.      buildMap[0].assetNames = assets;
    8.  
    9.      BuildPipeline.BuildAssetBundles("Assets/FetchedAssets", buildMap);
    10. }
    I tried the above code, running it in a script's Start()-method, the script being called only once as well. This threw a 'PlayerLoop called resursively!' error, which I don't understand since I removed any resursive calls to it.

    Right now it is being run in my client application for testing purposes (minimal working example), which does not have any AssetBundles set yet. In my understanding, however, I wouldn't need any set in any application anyhow, since I want to use scripts to generate the assetBundles from the .obj files and accompanying assets.

    I also tried running it from the concole navigated to the folder my Script.cs file is in and calling
    Code (CSharp):
    1. "C:\Program Files\Unity\Editor\Unity.exe" -batchmode -logfile -executeMethod "Script.BuildAssets" -quit"
    but this didn't work either (exactly nothing happened).

    I'm really not sure if what I'm doing is correct or can work at all, but this link http://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html seems to suggest exactly that.

    I would appreciate any help in this matter, since I think I'm on the right track, but maybe need a little pointer into the right direction.


    Thanks in advance

    Patrick
     
    Last edited: Aug 17, 2015
  2. Yeehaw

    Yeehaw

    Joined:
    Aug 15, 2015
    Posts:
    2
    After two hours, I found my mistake - the thing every developer hates most. A typo. :D

    I misspelled one of the assets referenced in the 'assets'-Array, so it couldn't be found. Now it works both in the editor and from the terminal. Seems to be possible to automatically create the assets bundles on a server by running a few scripts.