Add some way to change model texture in runtime. To make something like skins or animated textures.
I think this is coming soon based on mentions of being able to dynamically change textures and materials at runtime.
I am waiting too for this feature …
@britzl just got this issue in my project. I am downloading many png images from a server and I need to display them on the screen. I am using model component with a quad mesh. When I load an image and set it as a texture for one object on the screen, all objects get this image.
Is it still impossible to create a new separate resource for a model and load it with downloaded data?
What are the images/how are they being used?
Images are PNG icons for some sort of a catalog. I create a list view of items with a name label and an icon. Game objects are created with factory.create(), so they share the resource. I want to change the texture resource individually, but they change altogether.
You can try gui.new_texture. I don’t use it, but looks like it can change texture in runtime. Model still can’t change texture. PNG file save (SOLVED)
Are the sizes of the images consistent? https://github.com/subsoap/imagebatch might help as a starting point possibly.
Good stuff, but still won’t solve the issue entirely.
Hm. Any way to use gui texture in the game object world?
Transfer world coord to gui coords every frame, to update gui pos. Or create and attach gui to go. Not good way but no normal way, for changing texture.
that’s necessary feature.
Hm. Any way to use gui texture in the game object world?
Not an expert but I do think you should be able to kinda do it with some workarounds.
- Copy the GUI material from the builtins folder and changed the tag to
tile
. This will make it move with the camera (will be rendered in worldspace), but the positions changes from a parent go will not propegate to the gui. Therefore: - Create a script that tracks the delta position of the go and send that to the gui. This isn’t free because you would have to send a message to the gui each frame.
parent_gui.script
local position
function init(self)
position = go.get_position()
self.action = {x=position.x, y=position.y, dx=0, dy=0}
end
function update(self, dt)
position = go.get_position()
self.action.dx = self.action.x - position.x
self.action.dy = self.action.y - position.y
self.action.x = position.x
self.action.y = position.y
msg.post(".", "parent_update", self.action)
end
world_gui.gui_script
function init(self)
self.root = gui.get_node("root")
end
function on_message(self, message_id, message, sender)
if message_id == hash("parent_update") then
local p = gui.get_position(self.root)
p.x = p.x - message.dx
p.y = p.y - message.dy
gui.set_position(self.root, p)
end
end
Collection Setup
Is changing individual model textures at runtime still in the backlog?
It may be possible now with the resources update but that is something I have not gotten around to testing.
You can use resource properties to change texture: https://defold.com/manuals/script-properties/#resource-properties
Amazing, thanks!
Is it possible to change the texture of a material at runtime?
(or is this a new question?)
You can set the material of a model, or the individual textures of a model