0
\$\begingroup\$

I am making a game engine with C++ and OpenGL. Currently I'm stuck making the asset explorer. I would like to be able to import assets into an engine project and then when I open the project just use them in various game scenes (like in Unity). However the only thing I am doing right now is loading everything from the 'Assets' folder of the opened editor project. That is incredibly slow even when done asynchronously with multithreading. I don't understand how does Unity load assets so fast. I've noticed that it takes a while to import the assets for the first time but then it's very fast anytime you open the project after the first import. Is there any way to cache loaded assets? And should I generate all the buffers for OpenGL right on the asset import or should I wait for the asset to be 'used'?

Unity's asset explorer: enter image description here

All imported assets can be inspected like that, and then you can use them in the scenes (for example drag and drop a model into the scene): enter image description here

\$\endgroup\$
  • \$\begingroup\$ Two hints: 1) Peek inside the Unity Library folder sometime to see how it's pre-digested its imported assets into forms it can work with faster 2) Just because you can see a file in Unity's explorer doesn't strictly mean the whole thing is already loaded in memory, only enough to display the icon (the rest can wait until you actually click on the asset or open a scene that references it) \$\endgroup\$ – DMGregory Aug 2 at 11:49
  • \$\begingroup\$ Thank you for the great hints! As I looked into the library folder, I saw the .info files and stumbled upon this link when I tried to google what they were docs.unity3d.com/Manual/BehindtheScenes.html . I'm thinking of loading the asset's by loading their preview images, and then once they are inspected or used, I load them into memory completley. I am worried that it might be too slow because it takes some time to load a model especially if it has many triangles. Is there any better way of doing it? \$\endgroup\$ – Cantica Aug 2 at 12:19
  • \$\begingroup\$ The biggest mesh Unity can load as one piece is 65 thousand vertices. Assuming a position, texture coordinate, normal, and tangent for each that's 44 bytes per vertex, plus about another 65 K for the triangle indices, or about 2.8 MB of data total. Getting just a few megabytes off disk and into your GPU buffers is not likely to take long enough to cause a problem if you're just doing a straight read. Have you measured a big slowdown here? What step in the process seems to be slowest? Maybe that's a step you can do up-front during the data baking phase, rather than on demand. \$\endgroup\$ – DMGregory Aug 2 at 13:00
  • \$\begingroup\$ It's seems to be fine loading the object on Inspection. I was actually using a huge model for testing (which performed acceptably considering it's size). Thank you again for the great answers! \$\endgroup\$ – Cantica Aug 2 at 13:10
  • \$\begingroup\$ I was just giving hints — you're the one doing the work of implementing them as a solution. ;) If you have an approach that's solving your problem, please write it up as an Answer to share with other devs. :) \$\endgroup\$ – DMGregory Aug 2 at 13:24
1
\$\begingroup\$

I ended up solving the problem (thanks to DMGregory's hints) by generating meta files for each asset. The meta files contain the path to the preview image used in the asset explorer window, and import settings. Only when the asset is 'inspected' I fully load it into memory. That way the engine start's niceley without having to wait for files to load everytime, excpet for the first import where the meta files are generated.

\$\endgroup\$
0
\$\begingroup\$

If I understand correctly, you have a game engine with a GUI, and you want to display to the programmer the assets that the current project is using?

A lot of GUI programs (I believe unity too) create small thumbnails for images, which are a lot smaller in size than the original assets, so they can be displaying without issue. How big or small those should be depend on what your GUI looks like. You can make them as small as 50x50 and it will still be recognisable.

enter image description here original (220x220)

enter image description here resized (50x50)

Assuming that most assets are 200x200 or more, that means each asset now needs x4 times less resources, which can make loading faster but also reduced the amount of memory your engine needs to run. Keep in mind that even if the texture is resized for display purposes, when compiling your game you take the original texture, so the game is not affected by this change.

You may want to save the cache the resized images the first time this happens, this is why most programs take a while the first time they run and run way faster afterwards.

If you want to account for project scalability, you'd probably want to separate your assets into "categories" as well (maybe like per scene?) and load a specific group of assets when needed and not all assets at all times.

Note: Numbers are random-ish, you can use different numbers based on the needs of your project. The image was taken from Wikipedia - Cat intelligence

\$\endgroup\$
  • \$\begingroup\$ I'm not sure you understood me. My problem is not creating a GUI preview for the asset. Let's take for example a tree model. It's a model file located in some folder in the assets. When I run the project I want to be able to use that model in the scenes like in Unity. But if I load all of the models (and there are a lot of models in one 'Assets' folder) at startup, the engine will take a lot of time to start. I don't understand how Unity does it so fast. \$\endgroup\$ – Cantica Aug 2 at 11:10
  • \$\begingroup\$ @J.Doe Are you talking about creating a visible file hierarchy like a list? I'm not sure I understand exactly what you want the desired result to look like, could you post an image in your question about how Unity does it? That would help me understand it better. \$\endgroup\$ – TomTsagk Aug 2 at 11:13
  • \$\begingroup\$ Added screen shots and explanation. \$\endgroup\$ – Cantica Aug 2 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.