Is it possible to set the image of a mesh (tex property) to the texture of an atlas?
I have tried to get the following
local atlas = resource.get_atlas(ATLAS_URL)
local atlas_texture = atlas.texture
go.set(MESH_URL, “tex”, atlas_texture)
I can confirm that the atlas data and the atlas_texture are correct. But the last line gives
ERROR:GAMEOBJECT: Properties can not be of type ‘string’.
ERROR:SCRIPT: main/play/play.script:255: the property ‘tex’ of ‘/TEST_mesh_atlas#mesh’ must be a number
I have to admit I don’t quite understand what you mean with “Also note that you passed in the path when creating the resource.”. I called URL something that is a path in
“resource.atlas” (and the other resource properties) are there for you to be able to load a resource into your bundle.
If we didn’t have a reference, we wouldn’t know what content to build and bundle with the game.
The property “texture0” of the mesh, is there so that it may be read or set during runtime. Useful for changing a texture.
Note that you hash the path unnecessarily.
I refer to my previous statement: "Resources are referenced using hashes."
self.my_atlas is a resource path hash. All our resource properties are.
SO, you can do this:
and it does NOT work. I get the error: go.set failed because the value is unsupported
Then I have tried
local atlas = resource.get_atlas(self.my_atlas)
local atlas_texture = atlas.texture
go.set(MESH_URL, texture0, atlas_texture)
removing the hash and passing the texture directly. And still it does NOT work. I get the error: the property ‘texture0’ of ‘/TEST_mesh_atlas#mesh’ must be a hash.
So, there is something I don’t understand in your suggestion… What am I missing?
I’m sorry I tricked you a little bit, and I didn’t read your code in enough detail.
The texture0 accepts a texture (.texturec). It does not accept an atlas nor a tilesource.
And your example gets the texture name and hashes that. And that’s why it works.
Perhaps in the future, we can get a resource.get_texture(atlas)function to facilitate this.
As I wrote above, my aim was to set the texture of an atlas (created in the editor) as texture of a mesh. I have successfully achieved this as follows. I repeat somehow a previous post of mine in order to clearly have a solution at the end of this thread for future use.
First I defined a property in order to have the atlas included in the build / bundle: