playMaker

Author Topic: How can I dynamically apply a texture?  (Read 2802 times)

CambriaWiz

  • Playmaker Newbie
  • *
  • Posts: 3
How can I dynamically apply a texture?
« on: October 02, 2014, 05:20:31 PM »
So I have a game object (26 of them actually) that I'd like to dynamically assign textures to.  Think Scrabble tiles and I need to change the letters based on other actions in the game. This is accomplished easily enough by changing the texture on the mesh.  The challenge I'm having is doing this dynamically during game play.

My textures are named sequentially so I can get a string variable with the name of the texture.  I'd like to use that  name string to pass the texture to the Game Object's Material.  I can't seem to figure out how to do that.  What simple action am I overlooking?  Thanks in advance.

Best Wishes,
Rick

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: How can I dynamically apply a texture?
« Reply #1 on: October 02, 2014, 06:42:50 PM »
SET TEXTURE and SET MATERIAL should allow you to set textures at run-time.

CambriaWiz

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How can I dynamically apply a texture?
« Reply #2 on: October 02, 2014, 07:24:38 PM »
Thanks.  If I know what texture I want to apply, I can set it using SetMaterialTexture. My problem is that I don't know what Texture to apply until I've completed a prior action.  At that point, I know that I'll want to set the texture to the texture file named TextureA (for example).  The problem is that I don't know how to dynamically set a texture variable based on knowing the name of the file/asset.  If I can do that, then I can use SetMaterialTexture to put the right texture on my object.  Since I tend to ramble :D, I think that this is my core question:

How do I set the value of a texture variable to one of several possible textures at run time?

Thanks again,
Rick

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: How can I dynamically apply a texture?
« Reply #3 on: October 03, 2014, 06:51:43 AM »
If it was similar to Scrabble I'd have all the letters on one texture and change the offset depending on which tile I wanted to show.

Let’s say tile A is 1,1 and B is 1,2 etc...

Does that help?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: How can I dynamically apply a texture?
« Reply #4 on: October 03, 2014, 08:05:45 AM »
you can use a (Global) variable Material or Texture set it when that prior action is done and use that variable to set you texture/material.

or

you can use the Named Texture in Set Material Texture and use a String (Global) variable