keinekiv Posted June 14, 2017 Share Posted June 14, 2017 Hi again) I've managed to code a character and an item, however, the item remains invisible while in the inventory tab. It can be described, it can be dropped (and then shows up), so everything works, except it doesn't have a pic in the inventory. The code i'm using runs as follows local assets = { Asset("ANIM", "anim/oldcase.zip"), -- a standard asset Asset("ATLAS", "images/inventoryimages/oldcase.xml") -- a custom asset, found in the mod folder } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("oldcase") inst.AnimState:SetBuild("oldcase") inst.AnimState:PlayAnimation("idle", true) inst:AddComponent("fuel") inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/oldcase.xml" inst:AddComponent("inspectable") return inst end return Prefab("oldcase", fn, assets) So... I was trying to use [Tutorial] The Artist's Guide To Character/item Modding as a reference, but alas... Can anybody suggest what's wrong? Thank you for your help! Link to comment Share on other sites More sharing options...
BigMommaWolf Posted June 14, 2017 Share Posted June 14, 2017 @keinekiv Did you add an inventory image? Link to comment Share on other sites More sharing options...
keinekiv Posted June 14, 2017 Author Share Posted June 14, 2017 Yes, the tex file is in the directory where it should be, (I made a craftable custom item before and it works just fine) so I blame everything on the code this time... Link to comment Share on other sites More sharing options...
alainmcd Posted June 14, 2017 Share Posted June 14, 2017 Silly question: What does your oldcase.xml look like? It should be <Atlas><Texture filename="oldcase.tex" /><Elements><Element name="oldcase.tex" u1="0" u2="1" v1="0" v2="1" /></Elements></Atlas> Link to comment Share on other sites More sharing options...
Lumina Posted June 14, 2017 Share Posted June 14, 2017 (edited) What if you add this line ? inst.components.inventoryitem.imagename = "oldcase" Edited June 14, 2017 by Lumina Link to comment Share on other sites More sharing options...
keinekiv Posted June 15, 2017 Author Share Posted June 15, 2017 Thank you for your replies. My xml looks exactly the same, hmm. However, I'm not too sure if using the same u1, u2, v1, v2 values for both custom items is ok? What do those values mean anyway? I looked at another mod, downloaded from steam workshop, and it has something like u1="0.0078125" u2="0.9921875" v1="0.0078125" v2="0.9921875" Adding the line inst.components.inventoryitem.imagename = "oldcase" didn't help, unfortunately( Link to comment Share on other sites More sharing options...
alainmcd Posted June 15, 2017 Share Posted June 15, 2017 An "atlas" is a xml file that tells the game where to find a specific image, the "texture" is the file that contains the image or images (or "elements") and the u1, u2, v1 and v2 values correspond to the coordinates in the range 0-1 of the region where the image itself is found. Simply put, u1=0, u2=1, v1=0, v2=1 means "the whole texture corresponds to a single element", and u1=0.0078125, u2=0.9921875, v1=0.0078125, v2=0.9921875 means "ignore the outer pixels" (since 1/128 = 0.0078125 and 1-1/128 = 0.9921875). This is done so for performance reasons: when loading and accessing many images, it's better to have a single physical image (i.e. the file containing the images) and dividing it into several logical images (the "elements") that are then used. See for example data/images/inventoryimages.xml and inventoryimages.tex, where you have several hundred individual images packed into just two files, the atlas and the texture. Of course, none of this is relevant or helpful when you only have a couple of images in your mod. -- I just noticed your prefab is missing the mastersim check, which is necessary in DST - the tutorial you mention in the OP is for single player and most of it is the same, but this check is necessary. Add this to your fn after the AnimState calls and before adding components: inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end I'm not sure it'll solve the issue at hand, though. If it doesn't, would you care to share your oldcase.tex so I can see if I can manage to get it to show up? Link to comment Share on other sites More sharing options...
keinekiv Posted June 15, 2017 Author Share Posted June 15, 2017 Hi again. Well, yeah, adding those last lines to the code solved the issue, silly me, forgot to copy them too. Thanks so much, everyone, your help really means a lot <3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now