📖Unreal Plugin Codebase: Intro and FAQs
This page presents an overview of the main classes of the codebase in the Anything World plugin for Unreal Engine 5, plus some questions and answers related to using the functionality in potentially common use cases.
Codebase intro
The plugin uses Unreal Blueprints for UI and C++ classes for the rest of the logic, including the dynamic loading of meshes and related assets (textures, materials, animations) and actors and characters, as well as their behaviours. The Unreal coding conventions are followed and every class is well documented in code, but it is a good idea to start by having a look at some of the main classes in the following class diagram, followed by a brief explanation of their purpose.
A logged in user interacts with the Search Panel to browse for models, connecting to the Anything World web API via the AW API Manager singleton. The information from models is stored in a model entry map, where values are of the Model Entry struct, containing basic information and metadata of 3D models, as well as URLs pointing to their asset files. This information is visualised in the UI as Model Buttons, depicting a thumbnail of the model and some additional information.
If the user then clicks the button of a certain model, it triggers the downloading of its files and the model spawning and setup into the world. This process is done with the help of another singleton class, the AW Mesh Manager, which is added to the map unless you had one already there. The AW Mesh Manager checks the type of model that is present (static, animated or vehicle) to select the suitable loader (with Mesh Loader as abstract parent), that will create the actual actor that is placed into the world in a grid fashion:
Static models for which the FBX file is available are loaded using the Fbx Mesh Loader (which internally uses Unreal Engine’s Fbx Factory). The resulting actor is a AW Static Mesh Actor, having a Static Mesh Component.
Static models for which only an OBJ file is available are loaded using the Obj Mesh Loader, which also yields an AW Static Mesh Actor. OBJ support may be deprecated in the future and requires the parsing of a material file. Here the Fbx Factory is also used, but support for OBJ has less coverage so the Fbx Mesh Loader should be preferred when possible.
Rigged animated models are loaded using the Anim Fbx Mesh Loader, which inherits from the Fbx Mesh Loader but loads a skeleton and animations in addition to the mesh. The resulting actor is an AW Character, a type of Character that gets an animation Blueprint automatically created by default, as well as a simple random movement behaviour assigned (which requires a navigation mesh to work).
Vehicle models are loaded using the Vehicle Mesh Loader, also based on the Fbx Mesh Loader, but in charge of importing and setting up a hierarchy of multiple static meshes that form the parts of a vehicle, such as the chassis (main part or “body”) and each individual wheel (children components).
FAQ
Are dynamically loaded assets saved?
The content of 3D models are loaded to the “DynamicAssets” folder under the plugin’s “Content” directory. By default these Unreal assets are not persisted, but to do so you just need to select them in the content drawer and save them, like you would do for any regular asset that you imported manually. This way, they will be persisted if you restart the editor, meaning you can also save maps containing the assets. Note that the only assets that do not fully support saving options at this time are those loaded from OBJ meshes.
How to load Anything World models by code?
Ok, so you want to use our models without using our UI. That’s fine (just note there’s support for editor-time spawning only for now), you can follow this process:
Create an AW API Manager, to be able to request models. If you don’t want to use the login UI, pass your AW API key (available in your account page in Anything World’s website) to the function “GetAWAPIManagerInstance”.
Make a query to the AW API. You can use the function “StartModelSearch” from AW API Manager to make a search for all the models matching the query and fill the “ModelEntryMap” with the search results. If you are only interested in one model at a time, consider switching to using the “name” parameter of the “anything” endpoint of our web API, by implementing your custom function following the web API documentation.
Use the “StartLoadingMesh” function of AW Mesh Manager with the name of the mesh that you want to load, which should be one of the keys of the “ModelEntryMap” of AW API Manager resulting from the most recent search. “StartLoadingMesh” in AW Mesh Manager shows how the functions to load a mesh from URL need to be called, selecting the right loader and leading to spawn the right type of actor. If you don’t want to use the AW Mesh Manager, you can call these loaders in the way you see fit, as long as you provide them with the Model Entry struct obtained from a previous search to the API, or if you also modify how that is handled, to match your particular preferences.
Note that a “Callback” is passed to the loaders to decide how to set up the actor once the loader has spawned it. The AW Mesh Manager adjusts its pivot and position in a grid fashion, but you could potentially override that or pass an arbitrary function if you want to place the actor in a specific position or add any custom logic.
Can I load Anything World models at run-time?
Not yet, but this is planned for a future update.
Do you support Unreal Engine 4?
No.
Why are some models loaded as static even if they could be animated?
The models that are animated have a play icon in the top left corner of their thumbnails in their Model Button on the Search Panel. The others simply don’t have animations at this point. Some of them (for example some animals which aren’t animated yet) will be animated in the future, but others (for instance static objects) are likely to remain static. Vehicles will be animated using per-part rotation instead of rigging animation.
Last updated