engine.filesystem Functions
On the Engine file system initialization, all files and packages stored in the data folder are added to the virtual file system automatically. At that, content of the ZIP and UNG packages is loaded into RAM as is (so, you'd better not store heavy content (e.g. terrains) in the packages).
Files and packages stored outside the data directory are also added to the virtual file system, if they are mounted (i.e. referenced by a mount point).
File System functions:
- Provide control over asynchronous loading of files/meshes/images/nodes on demand under the data directory, including files in ZIP and UNG packages. Such packages are automatically handled by the Engine and all their files are automatically added to the file system.
- Allow adding directories (even with ZIP and UNG packages) that are outside the data directory and provide control over loading such files.
- Allow adding ZIP and UNG packages that are outside the data directory. After that, files in such packages are accessed in a usual way, by specifying a path to the file only inside the package.
- Allow caching files in the memory and adding files to blobs if they are accessed or modified multiple times at run time.
Also methods of the FileSystem class can be used when implementing your own importer from an external format to UNIGINE-native ones. For example, you can store only the original file on the disk, files in UNIGINE-native formats can be stored in the virtual file system only.
See also#
- engine.async Class to manage loading resources (files, images, meshes, and nodes) on demand.
- A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/systems/ folder:
- modifiers_00
- packages_00
- packages_01
FileSystem Class
Members
bool engine.filesystem.isBlobFile ( ) #
Checks if the given file is loaded to a blob.Arguments
Return value
true if the file is loaded to a blob successfully; otherwise, false.bool engine.filesystem.isBlobFile ( ) #
Checks if a file with the given GUID is loaded to a blob.Arguments
Return value
true if the file is loaded to a blob successfully; otherwise, false.bool engine.filesystem.isCacheFile ( ) #
Checks if the given file is loaded into cache.Arguments
Return value
true if the file is added into cache; otherwise, false.bool engine.filesystem.isCacheFile ( ) #
Checks if a file with the given GUID is loaded into cache.Arguments
Return value
true if the file is added into cache; otherwise, false.bool engine.filesystem.isFileExist ( ) #
Checks if the given file actually exists on the disk.Arguments
Return value
true if the file exists; otherwise, false.bool engine.filesystem.isFileExist ( ) #
Checks if a file with the given GUID actually exists.Arguments
Return value
true if the file exists; otherwise, false.engine.filesystem.getMTime ( ) #
Returns the time of the last modification of the given file.Arguments
Return value
Time of the last file modification. If there is no such file, -1 will be returned.engine.filesystem.getMTime ( ) #
Returns the time of the last modification of the file with the specified GUID.Arguments
Return value
Time of the last file modification. If there is no such file, -1 will be returned.bool engine.filesystem.addBlobFile ( ) #
Adds a file into a blob. It can be used for files that are frequently modified at run time (for example, images). After such file is loaded from a disk and written into a blob in the memory, its modifications can be saved fast into this blob.Arguments
Return value
true if the file is successfully added into a blob; otherwise, false.bool engine.filesystem.addBlobFile ( ) #
Adds a file with the given GUID into a blob. It can be used for files that are frequently modified at run time (for example, images). After such file is loaded from a disk and written into a blob in the memory, its modifications can be saved fast into this blob.Arguments
Return value
true if the file is successfully added into a blob; otherwise, false.bool engine.filesystem.addCacheFile ( ) #
Caches a file in the memory. It can be used for files that are accessed multiple times at run time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.Arguments
Return value
true if the file is successfully added to cache; otherwise, false.bool engine.filesystem.addCacheFile ( ) #
Caches a file in the memory with the given GUID. It can be used for files that are accessed multiple times at run time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.Arguments
Return value
true if the file is successfully added to cache; otherwise, false.bool engine.filesystem.loadPackage ( string path ) #
Loads an UNG or ZIP package into the file system. Note that the package should be mounted, otherwise it won't be loaded.Arguments
- string path - Package path. It can be a relative, absolute, network, or virtual path.
Return value
true if the package is loaded; otherwise, false.bool engine.filesystem.loadPackage ( string path, string extension ) #
Loads a package with the specified extension (ung, zip, or pak) into the file system. Note that the package should be mounted, otherwise it won't be loaded.Arguments
- string path - Package path. It can be a relative, absolute, network, or virtual path.
- string extension - Extension of a custom package, one of the following values:
- ung
- zip
- pak
Return value
true if the package is loaded; otherwise, false.bool engine.filesystem.removeBlobFile ( ) #
Removes a file from the blob. Blobbing can be used for files that are frequently modified at run time (for example, images). After such file is loaded from a disk and written into a blob in the memory, its modifications can be saved fast into this blob.Arguments
Return value
true if the file is removed successfully; otherwise, false.bool engine.filesystem.removeBlobFile ( ) #
Removes a file with the given GUID from the blob. Blobbing can be used for files that are frequently modified at run time (for example, images). After such file is loaded from a disk and written into a blob in the memory, its modifications can be saved fast into this blob.Arguments
Return value
true if the file is removed successfully; otherwise, false.bool engine.filesystem.removeCacheFile ( ) #
Removes a cached file from the memory. Caching can be used for files that are accessed multiple times at run time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.Arguments
Return value
true if the file is successfully removed from cache; otherwise, false.bool engine.filesystem.removeCacheFile ( ) #
Removes a cached file with the given GUID from the memory. Caching can be used for files that are accessed multiple times at run time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.Arguments
Return value
true if the file is successfully removed from cache; otherwise, false.int engine.filesystem.getNumModifiers ( ) #
Returns the total number of file modifiers registered in the file system.Return value
Number of modifiers.String engine.filesystem.getModifier ( int num ) #
Returns the name of the given modifier.Arguments
- int num - ID number of the modifier.
Return value
Modifier name.void engine.filesystem.addModifier ( string name ) #
Registers a new modifier in the file system.Arguments
- string name - Modifier name.
void engine.filesystem.removeModifier ( string name ) #
Unregisters a given modifier in the file system.Arguments
- string name - Modifier name.
void engine.filesystem.clearModifiers ( ) #
Unregister all modifiers in the file system.bool engine.filesystem.removePackage ( string path ) #
Unloads an UNG or ZIP package from the file system.Arguments
- string path - Package path. It can be a relative, absolute, network, or virtual path.
Return value
true if the package is removed; otherwise, false.bool engine.filesystem.isAssetPath ( string path ) #
Returns a value indicating if the given path has a valid asset path format (e.g. asset://1.tga).Arguments
- string path - Path to be checked.
Return value
true if the given path has a valid asset path format; otherwise, false.UGUID engine.filesystem.generateGUID ( ) #
Generates a new GUID.Return value
New filesystem GUID if is was generated successfully; otherwise, an empty GUID.bool engine.filesystem.setGUID ( string path, UGUID guid ) #
Sets the specified GUID for the given file.Arguments
- string path - File path. It can be a relative, absolute, network, or virtual path.
If you want to specify a path to an asset, you should use the asset path format (asset://). Otherwise, if you specify the regular path to the asset, it will be treated as the path to its runtime file (if any) from the .runtimes folder.
- UGUID guid - GUID to be set for the file.
Return value
true if the GUID is set successfully; otherwise, false.UGUID engine.filesystem.getGUID ( string path ) #
Returns the GUID (if it exists) for the given file.Arguments
- string path - File path. It can be a relative, absolute, network, or virtual path.
If you want to specify a path to an asset, you should use the asset path format (asset://). Otherwise, if you specify the regular path to the asset, it will be treated as the path to its runtime file (if any) from the .runtimes folder.
Return value
File GUID if it exists; otherwise, an empty GUID.bool engine.filesystem.isGUIDPath ( string path ) #
Returns a value indicating if the given path has a valid GUID path format (e.g. "guid://e231e15beff2309b8f87c30b2c105cc4d2399973)".Arguments
- string path - Path to be checked.
Return value
true if the given path has a valid GUID path format; otherwise, false.bool engine.filesystem.saveGUIDs ( string path, bool binary = false ) #
Saves all file system GUIDs to the specified file in the specified format (json or binary).Arguments
- string path - Path to the file, where file system GUIDs are to be stored.
- bool binary - Binary file format flag. When the flag is set to true, the file system will save GUIDs to a binary file; otherwise, to a JSON file.
Return value
true if all file system GUIDs are saved successfully; otherwise, false.bool engine.filesystem.loadGUIDs ( string path ) #
Loads file system GUIDs from the specified file.Arguments
- string path - Path to the file, where file system GUIDs are stored.
Return value
true if file system GUIDs are loaded successfully; otherwise, false.void engine.filesystem.clearExternPackages ( ) #
Removes all external packages from the file system.engine.filesystem.getExtension ( ) #
Returns the extension for the given file.Arguments
Return value
File extension in lower case, if any; otherwise, an empty string.engine.filesystem.getExtension ( ) #
Returns the extension for a file with the specified GUID.Arguments
Return value
File extension in lower case if any; otherwise, an empty string.engine.filesystem.getMount ( ) #
Returns a mount point for the specified path.Arguments
Return value
FileSystemMount class instance on success; otherwise, nullptr.bool engine.filesystem.saveMountFile ( string umount_path ) #
Saves the specified *.umount file.Arguments
- string umount_path - Mount point file path.
Return value
true if the specified *.umount file is saved successfully; otherwise, false.engine.filesystem.getMount ( ) #
Returns a mount point for the specified GUID.Arguments
Return value
FileSystemMount class instance on success; otherwise, nullptr.void engine.filesystem.getMounts ( ) #
Returns a list of all mount points currently used by the file system and puts the to the specified output buffer.Arguments
FileSystemMount engine.filesystem.getRootMount ( ) #
Returns the root mount of the file system. It mounts the data folder to the root of the virtual file system. The root mount cannot be unmounted.Return value
FileSystemMount class instance for the root mount of the virtual file system.FileSystemMount engine.filesystem.createMount ( string absolute_path, string virtual_path, int access ) #
Adds a new mount point for the specified external folder/package, virtual path and access mode. All mounted files are automatically added as known to the virtual file system.Arguments
- string absolute_path - Absolute path to the mounted folder/package.
- string virtual_path - Virtual path to the folder to which the contents of the external folder/package is to be mounted.
- int access - Mount point access mode, one of the FILESYSTEM_MOUNT_ACCESS_* values.
Return value
FileSystemMount class instance, if it was created successfully; otherwise, nullptr.FileSystemMount engine.filesystem.addMount ( string umount_path ) #
Adds a new mount point using the data from the specified *.umount file. All mounted files are automatically added as known to the virtual file system.Arguments
- string umount_path - Absolute path to a *.umount file.
Return value
FileSystemMount class instance, if it was created successfully; otherwise, nullptr.bool engine.filesystem.removeMount ( string path ) #
Unmounts a mount point with a given path.Arguments
- string path - Absolute path to the mounted folder/package.
Return value
true if the mount point with a given path is successfully unmounted; otherwise, false.void engine.filesystem.clearMounts ( ) #
Unmounts all mount points.void engine.filesystem.getPackageVirtualFiles ( ) #
Saves the list of names for all virtual files stored in the specified package to the specified string buffer.Arguments
void engine.filesystem.getPackageVirtualFiles ( ) #
Saves the list of names for all virtual files stored in a package with the specified name and extension to the specified string buffer.Arguments
void engine.filesystem.getVirtualFiles ( ) #
Saves the list of names for all known files registered in the file system to the specified string buffer.Arguments
bool engine.filesystem.isVirtualFile ( ) #
Checks if the given file is known to the virtual file system.Arguments
Return value
true if the file is known to the virtual file system; otherwise, false.bool engine.filesystem.isVirtualFile ( ) #
Checks if a file with the given GUID is known to the virtual file system and has a virtual path registered.Arguments
Return value
true if the file is known to the virtual file system; otherwise, false.bool engine.filesystem.addVirtualFile ( string path, UGUID guid, bool must_exist = false ) #
Registers the regular file name as known virtual file with the given GUID and appends it to the map used for fast searching. This method should be used when you need to add, for example, a new content to the project.Arguments
- string path - File path. It can be a relative, absolute, network, or virtual path.
If you want to specify a path to an asset, you should use the asset path format (asset://). Otherwise, if you specify the regular path to the asset, it will be treated as the path to its runtime file (if any) from the .runtimes folder.
- UGUID guid - File GUID.
- bool must_exist - A flag indicating whether the specified file must exist.
Return value
true if the file name is appended successfully; otherwise, false.UGUID engine.filesystem.addVirtualFile ( bool must_exist = false ) #
Registers the regular file name as known virtual file and appends it to the map used for fast searching. This method should be used when you need to add, for example, a new content to the project.Arguments
- bool must_exist - A flag indicating whether the specified file must exist.
Return value
File GUID if it was registered successfully or an empty GUID, otherwise.bool engine.filesystem.renameVirtualFile ( ) #
Renames the specified known virtual file.Arguments
Return value
true if the file is renamed successfully; otherwise, false.bool engine.filesystem.renameVirtualFile ( ) #
Renames the specified known file and assigns it the specified new GUID.Arguments
Return value
true if the file is renamed successfully; otherwise, false.bool engine.filesystem.renameVirtualFile ( ) #
Renames the known virtual file with the given GUID.Arguments
Return value
true if the file is renamed successfully; otherwise, false.bool engine.filesystem.renameVirtualFile ( ) #
Renames the known virtual file with the given GUID and assigns it the specified new GUID.Arguments
Return value
true if the file is renamed successfully; otherwise, false.bool engine.filesystem.removeVirtualFile ( ) #
Removes the virtual file with the given name.Arguments
Return value
true if the file is removed successfully; otherwise, false.bool engine.filesystem.removeVirtualFile ( ) #
Removes the virtual file with the given GUID.Arguments
Return value
true if the file is removed successfully; otherwise, false.bool engine.filesystem.changeVirtualFile ( ) #
Marks the virtual file with the given name as modified. The corresponding CALLBACK_FILE_CHANGED signal is emitted. This method is used to notify the Engine that a resource has been modified and needs to be updated.Arguments
Return value
true if the file is successfully marked as modified; otherwise, false.bool engine.filesystem.changeVirtualFile ( ) #
Marks the virtual file with the given GUID as modified. The corresponding CALLBACK_FILE_CHANGED signal is emitted. This method is used to notify the Engine that a resource has been modified and needs to be updated.Arguments
Return value
true if the file is successfully marked as modified; otherwise, false.void engine.filesystem.removeNonExistingVirtualFiles ( ) #
Removes all non-existing virtual files from the File System. These files aren't physically exist on the disk, however, they are added to the virtual file system. For example, it can be a blob or a cache file.bool engine.filesystem.isDiskFile ( ) #
Returns a value indicating if the specified file path is a path to a file on disk (i.e. not a package, a blob, or a cache file).Arguments
Return value
true if the specified file path is a path to a file on disk; otherwise, false.bool engine.filesystem.isPackageFile ( ) #
Returns a value indicating if the specified file path is a path to a file inside a ZIP or UNG package.Arguments
Return value
true if the specified file path is a path to a file inside a ZIP or UNG package; otherwise, false.String engine.filesystem.resolvePartialVirtualPath ( string path ) #
Converts the given partial path to a full virtual one.// convert partial virtual to full virtual path
string full_virtual_path = engine.filesystem.resolvePartialVirtualPath("image_1.tga"); // project/image_1.tga is returned
// use the converted path
Image(full_virtual_path);
Arguments
- string path - Partial path to be resolved.
Return value
Full virtual path.engine.filesystem.getVirtualPath ( ) #
Resolves a virtual path for the given file path. The following examples show particular cases of the method usage:- If the given path is known for the virtual file system, the following can be returned:
In all cases, an empty string is returned: a virtual path is always returned relative to the data directory, and in the example, the data directory itself is specified. If you specify a known file inside it, the corresponding virtual path will be returned:
string s1, s2, s3; // absolute path to the folder s1 = engine.filesystem.getVirtualPath("D:/Unigine/data"); // an empty string s2 = engine.filesystem.getVirtualPath("D:/Unigine/data/"); // an empty string // path to assets in the folder s3 = engine.filesystem.getVirtualPath("asset://D:/Unigine/data"); // an empty string s4 = engine.filesystem.getVirtualPath("asset://D:/Unigine/data/"); // an empty string
string s = engine.filesystem.getVirtualPath("D:/Unigine/data/1.tga"); // "1.tga"
- If the given path is unknown for the virtual file system, the following can be returned:
In all cases, the normalized path to the folder is returned, as the specified folder is unknown for the virtual file system, and, therefore, no virtual path can be returned. The same is for files, for example:
// absolute path to the folder s1 = engine.filesystem.getVirtualPath("C:/temp"); // "C:/temp" s2 = engine.filesystem.getVirtualPath("C:/temp/"); // "C:/temp" // path to assets in the folder s3 = engine.filesystem.getVirtualPath("asset://C:/temp"); // "C:/temp" s4 = engine.filesystem.getVirtualPath("asset://C:/temp/"); // "C:/temp"
s = engine.filesystem.getVirtualPath("C:/temp/1.tga"); // "C:/temp/1.tga"
- If the given path is the path to a mounted file. Here mount_1 is the mount_1.umount mount point. Note that in the example below, the 1.tga asset has no runtime files. If an asset has a runtime file, the virtual path to this runtime file (stored in the .runtimes folder of the mount point) will be returned.
// virtual path to the file specified as an absolute one s1 = engine.filesystem.getVirtualPath("D:/Unigine/data/mounts/mount_1/1.tga"); // "mounts/mount_1/1.tga" // absolute path to the file s2 = engine.filesystem.getVirtualPath("D:/extern_content/1.tga"); // "mounts/mount_1/1.tga" // full virtual path to the file s3 = engine.filesystem.getVirtualPath("mounts/mount_1/1.tga"); // "mounts/mount_1/1.tga"
- If the given path is the path to a mounted file stored in the nested mount points. Here mount_1 and mount_2 are the mount_1.umount and mount_2.umount mount points correspondingly. Note that in the example below, the 1.tga asset has no runtime files. If an asset has a runtime file, the virtual path to this runtime file (stored in the .runtimes folder of the mount point) will be returned.
// virtual path to the file specified as an absolute one s1 = engine.filesystem.getVirtualPath("D:/Unigine/data/mounts/mount_1/mount_2/1.tga"); // "mounts/mount_1/mount_2/1.tga" // absolute path to the file s2 = engine.filesystem.getVirtualPath("D:/extern_content_2/1.tga"); // "mounts/mount_1/mount_2/1.tga" // full virtual path to the file s3 = engine.filesystem.getVirtualPath("mounts/mount_1/mount_2/1.tga"); // "mounts/mount_1/mount_2/1.tga"
Arguments
Return value
Virtual path to the file relative to the data folder.engine.filesystem.getVirtualPath ( ) #
Resolves a virtual path for the given file path.Arguments
Return value
Virtual path to the file relative to the data folder.engine.filesystem.getAbsolutePath ( ) #
Resolves an absolute path for the given file path. The following examples show particular cases of the method usage:- If the given path is known for the virtual file system, the following can be returned:
string s1, s2, s3, s4; // absolute path to the folder s1 = engine.filesystem.getAbsolutePath("D:/Unigine/data"); // "D:/Unigine/data" s2 = engine.filesystem.getAbsolutePath("D:/Unigine/data/"); // "D:/Unigine/data" // absolute path to assets in the folder s3 = engine.filesystem.getAbsolutePath("asset://D:/Unigine/data"); // "D:/Unigine/data" s4 = engine.filesystem.getAbsolutePath("asset://D:/Unigine/data/"); // "D:/Unigine/data"
- If the given path is unknown for the virtual file system, the following can be returned:
// absolute path to the folder s1 = engine.filesystem.getAbsolutePath("C:/temp"); // "C:/temp" s2 = engine.filesystem.getAbsolutePath("C:/temp/"); // "C:/temp" // absolute path to assets in the folder s3 = engine.filesystem.getAbsolutePath("asset://C:/temp"); // "C:/temp" s4 = engine.filesystem.getAbsolutePath("asset://C:/temp/"); // "C:/temp"
- If the given path is the path to a mounted file. Here mount_1 is the mount_1.umount mount point. Note that in the example below, the 1.tga asset has no runtime files. If an asset has a runtime file, the absolute path to this runtime file (stored in the .runtimes folder of the mount point) will be returned.
// virtual path specified as an absolute one s1 = engine.filesystem.getAbsolutePath("D:/Unigine/data/mounts/mount_1/1.tga"); // "D:/extern_package/1.tga" // absolute path s2 = engine.filesystem.getAbsolutePath("D:/extern_package/1.tga"); // "D:/extern_package/1.tga" // virtual path s3 = engine.filesystem.getAbsolutePath("mounts/mount_1/1.tga"); // "D:/extern_package/1.tga"
- If the given path is the path to a mounted file stored in the nested mount points. Here mount_1 and mount_2 are the mount_1.umount and mount_2.umount mount points correspondingly. Note that in the example below, the 1.tga asset has no runtime files. If an asset has a runtime file, the absolute path to this runtime file (stored in the .runtimes folder of the mount point) will be returned.
// virtual path specified as an absolute one s1 = engine.filesystem.getAbsolutePath("D:/Unigine/data/mounts/mount_1/mount_2/1.tga"); // "D:/extern_content_2/1.tga" // absolute path s2 = engine.filesystem.getAbsolutePath("D:/extern_content_2/1.tga"); // "D:/extern_content_2/1.tga" // virtual path s3 = engine.filesystem.getAbsolutePath("mounts/mount_1/mount_2/1.tga"); // "D:/extern_content_2/1.tga"
- If the given path is a network path:
s1 = engine.filesystem.getAbsolutePath("//studio/work/shared_content/images.zip"); // "//studio/work/shared_content/images.zip" s2 = engine.filesystem.getAbsolutePath("\\\\studio\\work\\shared_content\\images.zip"); // "//studio/work/shared_content/images.zip"
Arguments
Return value
Absolute path to the file.engine.filesystem.getAbsolutePath ( ) #
Resolves an absolute path for the given file GUID.