Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thatanimator · Nov 01, 2012 at 05:07 AM · texturematerialruntimechange

Texture change on multi material character

Good day! I'm trying to trigger different face textures using animation events. I've tried using different variables, from gameobjects (the player) to materials. I've checked several threads on Unity Answers, but all answers are scripts that point to the mainTexture, which it does anyways by default..

I mean, the script I have now works, as far as triggering texture changes from the animation. But it changes the wrong texture!

Any ideas of how to solve this would be appreciated, thank you!

var mat : Material;

as well as Materials[]; and then call Materials[2]; in the script.

none of those work, and I get unassigned bugs from them.

I have also tried making a custom shader for the part of the character I want to change the texture of, and changing the standard Properties _MainTex to "_FaceTex" and then call that in the script, but that doesn't work either!

this is what I have right now, what it does is changing the texture of the first texture it can find, rather than the one I'd want it to change.

 var player : GameObject;
 
 var neutral : UnityEngine.Texture;
 var angry : UnityEngine.Texture;
 var scream : UnityEngine.Texture;
      
      
      
 function FaceNeutral () {
     player.renderer.material.mainTexture = neutral;
 }
 function FaceScream () {
     player.renderer.material.mainTexture = scream;
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thatanimator · Dec 04, 2012 at 08:39 PM 0
Share

I still haven't solved this problem.

http://www.youtube.com/watch?v=tZ8wIy-cpYo

Here's a video describing the problem a bit further.

Hoping that somebody can help me with this one! :) Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by richard3d · Dec 04, 2012 at 09:37 PM

I think this is what you are looking for http://docs.unity3d.com/Documentation/ScriptReference/Material.GetTexture.html

This is how you can access named textures from the material. I am assuming your shader or material has some texture samplers that are named faceTexture, bodyTexture or something along those lines and maybe you just want to change the face texture. Hope this helps - R

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thatanimator · Dec 05, 2012 at 09:03 AM 0
Share

thank you for the reply!

yeah I've checked ou the script ref and other unity answers, but they all seem to focus on the $$anonymous$$ainTex stuff. the example script for the GetTexture is horrible and doesn't apply to my problem. I have tried their script straight up, and it works if I do .GetTexture ("$$anonymous$$ainTex"), it tells the console what texture is assigned and what not. But if I change it to _FaceTex, it tells me there's no texture connected.

As far as I understand, the whole _NameTex is the name of the property in the shader, which in my case is _FaceTex, so I haven't overlooked that part..

Even trying "renderer.material.SetTexture("FaceTex", texture);" only works if I write $$anonymous$$ainTex.

HAS to be something related to the _FaceTex property I have in my shader I assume? it doesn't differ that much from a normal unlit shader though, just that property name..

avatar image richard3d · Dec 06, 2012 at 11:08 PM 0
Share

Have you tried removing the underscore before FaceTex? I believe the underscored names are only for referencing pre-defined texture units like the Cubemap etc. Unless the name in your shader literally says _FaceTex also.

avatar image richard3d · Dec 06, 2012 at 11:40 PM 0
Share

Also, if you wouldn't $$anonymous$$d pasting your shader code it could give some more insight as well

avatar image thatanimator · Dec 07, 2012 at 01:05 AM 0
Share

Thank you again for the comments! I tried removing the underscore before FaceTex, didn't work. No underscore before $$anonymous$$ainTex didn't work either, but as soon as I add the underscore _$$anonymous$$ainTex, the hair starts changing textures again.

The video I posted can be viewed in glorious 1080p so you can read the shaders and javascript files in there. But here is the shader file, used for the material which has the face textures on it;

http://pastebin.com/TGVPrFzZ

The javascript attached to the player, looks like this; (currently set to $$anonymous$$ainTex, but this is the part I keep changing back and forth between $$anonymous$$ainTex and _FaceTex)

http://pastebin.com/ZgPfwCEW

And is used as a trigger in the animation. For later I want him to look angry or whatever, at certain parts of fight animations.

avatar image richard3d · Dec 08, 2012 at 05:58 PM 0
Share

Hey thanks for posting your code, I was able to make it run without any major changes so it must be something else that is the root of your problem. I did the following to make it work: create a blank material and assign the shader to it. Create a cube gameobject and assign the material and the script to it. I modified the script a bit so it wouldnt have to point to a specific gameobject (since in this case it is already attached to the cube). I also added the Update function to the script and just had it call FaceNeutral the whole time (these were the only changes). So take a look at your setup again and maybe use some debug logging to make sure your functions are getting called etc. Good luck! Also if you wouldn't $$anonymous$$d marking this as answered it would be awesome.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing GameObject texture? 4 Answers

Texture an Object at Runtime, work through help needed. 0 Answers

How can i change detail texture? 1 Answer

Change Material of an Object. 5 Answers

referring to a particular material 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges