Load Resource from memory at runtime

I really need to add a model to my scene that I download from our server at runtime.
Getting the file over the net is easy… HTTP Get etc.

Now how do I get the resourcecache to load it??

Tried lots of stuff with MemoryBuffer but no luck 8(
Also tried writing to mass storage but again no Bueno…

Might have found a happy path… I’ll post the results for all once confirmed and cleaned up.

1 Like

Maybe Resource::LoadFile and then ResourceCache::AddManualResource?
I have not tried this.

Make sure you set the (file?) name on the resource before adding it as a manual resource. What’s happening when you try using the MemoryBuffer?

Probably stating the obvious here but the standard way to do this is through Scene::AddRequiredPackageFile and Network::SetPackageCacheDir.

Is this not possible in your situation?


That sounds like what I should explore… but here’s our hacky ‘working’ version as we spike this functionality:

        public Model LoadModel()
            var _model = scene.GetComponent<StaticModel>(true);

                // This mimics the bytes we will get from the server
                var file = ResourceCache.GetFile("Models/Sphere.mdl");
                byte[] fileBytes = new byte[file.Size];
                file.Read(fileBytes, file.Size);

                //This is stuffing it into the Urho system as if we got it off the network etc...
                MemoryBuffer buff = new MemoryBuffer(fileBytes);
                _model.Model = new Model();
            catch (Exception ex)

            return _model.Model;

You’ll notice it’s C# and I’ve already read that this is not the C# forum but there is no other documentation for us-- it is just a thin wrapper to the same bits covered in this forum.
So it’s what I have to work with, ya know?
Someday you guys may need to do a Xamarin thing, I’ll be glad to help with the various gotchas I have encountered.