From a199e2b2631064015daab94780e06bfbb24ae3d5 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 24 Sep 2019 16:05:49 +0200 Subject: Mention `MeshLibrary.get_item_preview()` not working in running project --- doc/classes/MeshLibrary.xml | 14 ++++++++------ scene/resources/mesh_library.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/classes/MeshLibrary.xml b/doc/classes/MeshLibrary.xml index 041d1fa80d..44dc4f334f 100644 --- a/doc/classes/MeshLibrary.xml +++ b/doc/classes/MeshLibrary.xml @@ -4,7 +4,7 @@ Library of meshes. - Library of meshes. Contains a list of [Mesh] resources, each with name and ID. This resource is used in [GridMap]. + A library of meshes. Contains a list of [Mesh] resources, each with a name and ID. This resource is used in [GridMap]. @@ -13,7 +13,7 @@ - Clear the library. + Clears the library. @@ -22,7 +22,7 @@ - Create a new item in the library, supplied an id. + Create a new item in the library, supplied as an ID. @@ -80,6 +80,8 @@ + Returns a generated item preview (a 3D rendering in isometric perspective). + [b]Note:[/b] Since item previews are only generated in an editor context, this function will return an empty [Texture] in a running project. @@ -94,7 +96,7 @@ - Gets an unused id for a new item. + Gets an unused ID for a new item. @@ -114,7 +116,7 @@ - Sets the mesh of the item. + Sets the item's mesh. @@ -125,7 +127,7 @@ - Sets the name of the item. + Sets the item's name. diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index ad8da63abf..f04af29761 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "mesh_library.h" +#include "core/engine.h" bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { @@ -201,6 +202,11 @@ Transform MeshLibrary::get_item_navmesh_transform(int p_item) const { Ref MeshLibrary::get_item_preview(int p_item) const { + if (!Engine::get_singleton()->is_editor_hint()) { + ERR_PRINT("MeshLibrary item previews are only generated in an editor context, which means they aren't available in a running project."); + return Ref(); + } + ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].preview; } -- cgit v1.2.3