Loops through an Instance and returns a dictionary containing arrays of every asset it found. By assets, I am referring to assets that the engine has to download, like Decals, Meshes, Sounds, etc.
It is compiled (hence the --!native flag). For reference, in my tests, when compiled it normally takes ~0.002 seconds to run. When it’s not compiled, it takes ~0.008 seconds.
Module link: Asset Dictionary
Documentation: Asset Dictionary Documentation
GitHub: bloodbonnieking/Roblox-Asset-Dictionary
Updates
V1.1:
- Added different tables for every asset
- Fixed the 2nd argument not doing anything
- Changed the elseifs to cases (table)
- Added some exceptions and errors
V1.2:
- Fixed a coding oversight that would only sort AssetDictionary, DecalDictionary and TextureDictionary
- Added a new optional boolean “Reverse”. Read more in the documentation.
V1.3:
- Added pants and shirt support
V1.4:
- Fixed supported assets getting skipped over for “not being supported”
- Switched to numeric for loop to hopefully speed stuff up
- Switched to using typeof() for exceptions
V1.5:
- Added a few memory related functions (read more in the documentation)
- Changed the AssetDictionary table to GeneralDictionary, and finally deprecated it.
(REMOVED COMPLETELY IN V1.6)
V1.6:
- Removed GeneralDictionary (it was useless and it made the script unreadable)
- Added type notations (tried to add type notations before in a few unreleased versions because I didn’t know that ? makes it optional)
- Removed nil checks
- Made errors tell you the argument name instead
- Added a new argument, read more in the documentation
V1.7:
- Moved documentation (and made it better)
- Moved animation dictionary to above image labels, this does not affect anything and is merely tidying up the code a bit
- Changed . to : for functions for slight consistency
- Video support
- ClearTable now needs the asset type name to avoid accidental clearing of non-related tables
- Errors are now level 2 errors
- Added a print argument for debugging
V1.8:
- Cleaned up the code, got rid of useless things and improved it a bit
- Moved dictionaries into ModuleDictionary.Dictionaries. This isn’t a big change, but possibly a tedious one.
- Got rid of “temporary tables” which were the tables that weren’t share across scripts.
- Created a new argument, ClearTables which will clear all of the tables before appending the ids (default is true)
- Removed some useless exceptions
- Script uses native Luau now (from my testing, it used to take a solid second without native and now it takes like less than half a second) (read more here: Luau Native Code Generation Preview [Studio Beta])
- Made ClearTable WAY more compact
- ClearTable now accepts strings with “Dictionary”, not just without
V1.8.1 (not wasting a version number) - The GetDictionary scope no longer ends before the return (that wasn’t intentional)
- Print will now print a benchmark (note: the time starts as soon as the function is called and the print happens at the end, which means other if statements may change the result.)
V1.9:
- Added support for particle emitters
- that’s it
V2:
- Completely rewritten
- Dictionaries now contain Instances instead of AssetIDs. There will be a new argument added soon to return to the old behavior if you want, but due to roblox messing mesh and texture properties up (cough)
it will take a bit longer. - To reflect this, and for consistency, GetDictionary is now GetAssets
- Removed a lot of the bloat and.. questionable practices
- Dictionaries are now returned instead of being global, avoiding race conditions
- Removed cases entirely and instead it finds the appropriate table based off the ClassName
- Due to the prior change, VideoDictionary and ParticleDictionary are now VideoFrameDictionary and ParticleEmitterDictionary respectively.
- Removed sorting and reversing, because although they did have use cases, unlike a lot of the other arguments, I did not want to bother with maintaining it and ultimately I doubt people are using this module to create Videos anymore.
- Changed Print to DebugWarn and now instead of printing a bunch of useless debug data it will throw a warning only if it encounters an instance that is not an Asset. By default it is false so it doesn’t pointlessly spam the console with warnings.
V2.1: - Fixed a bug where MeshParts were falsely flagged as unsupported due to MeshDictionary not using the correct name (MeshPartDictionary)
- Added SpecialMesh support.
What’s supported:
- Decals
- Textures
- Sounds
- Meshes
- Animations
- Image labels
- Image buttons
- Video frames
- Shirts
- Pants
- Particle emitters
Here is the code if you don’t want to open it in a place:
--!native
local ModuleDictionary = {}
local TemplateDictionaries = {
GeneralDictionary = {};
DecalDictionary = {};
TextureDictionary = {};
SoundDictionary = {};
MeshPartDictionary = {};
SpecialMeshDictionary = {};
AnimationDictionary = {};
VideoFrameDictionary = {};
ImageLabelDictionary = {};
ImageButtonDictionary = {};
ShirtDictionary = {};
PantsDictionary = {};
ParticleEmitterDictionary = {}
}
local function AddToTable(Dictionary, TargetArray, Warn)
for _, Asset: Instance in pairs(TargetArray) do
local AssetDictionary = Dictionary[`{Asset.ClassName}Dictionary`]
if not AssetDictionary then
if Warn then
warn(`Invalid Instance type. Expected Asset, got {Asset:GetFullName()}: {Asset.ClassName}`)
end
continue
end
table.insert(AssetDictionary, Asset)
table.insert(Dictionary.GeneralDictionary, Asset)
end
end
function ModuleDictionary:GetAssets(Target: Instance, Recursive: boolean?, DebugWarn: boolean?)
local TargetArray
assert(typeof(Target) == "Instance", `GetDictionary expects Target to be an instance, got {tostring(Target)}`)
if typeof(Recursive) ~= "boolean" then Recursive = false end
if typeof(DebugWarn) ~= "boolean" then DebugWarn = false end
local Dictionaries = table.clone(TemplateDictionaries)
if not Recursive then
TargetArray = Target:GetChildren()
elseif Recursive then
TargetArray = Target:GetDescendants()
end
AddToTable(Dictionaries, TargetArray, DebugWarn)
return Dictionaries
end
return ModuleDictionary
