Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by DeathByTouchy · Oct 08, 2015 at 10:51 AM · textureoffset

mainTextureOffset not updating via script

Hey Guys, I'm attempting to scroll a texture by updating its .y offset value in script. In the inspector, when I'm not running the script, changing the y value works fine and the texture scrolls as expected.
When I run my script, which simply increments the y value, nothing happens. The .y offset value stays at zero and the texture doesn't move. However...while the script is still running, when I click in the .y field of the offset in the inspector it instantly updates to the correct .y value...but the texture does not move. The texture is set to "Repeat". Its like the .y value is being updated correctly but is not be applied to the material/texture. Any thoughts on what I'm missing? Cheers Touchy

public Vector2 currentOffset;

 // Use this for initialization
 void Start () 
 {
     currentOffset = new Vector2(0,0);
 }
 
 // Update is called once per frame
 void Update () 
 {
     if(Input.GetKey (KeyCode.U))
     {
         currentOffset.y += 1;
         gameObject.GetComponent<Renderer>().material.mainTextureOffset = currentOffset;
         Debug.Log (currentOffset);

     }
 }
Comment
Add comment · Show 2
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 Owen-Reynolds · Oct 08, 2015 at 05:04 PM 1
Share

When this first runs, I think it makes a copy of the $$anonymous$$aterial (anything that modifiers $$anonymous$$aterials does that.) So you might be looking at the original $$anonymous$$at, and not the one on your object (should have "(Instance)" added in the Inspector.)

You're also adding 1 to y, which is supposed to do nothing.

avatar image DeathByTouchy Owen-Reynolds · Oct 08, 2015 at 07:10 PM 0
Share

Thanks Owen - yep I'm definitely trying to offset the material that is an "instance".

I've jigged around - now when I'm running my script the offset value is now updating in the inspector as expected (not sure what I did to fix that bit...). However, the texture still does not offset to the new value unless I manually change the value in the inspector while the script is running. So yeah, it's like the offset value isn't being applied to this particular instance of the material.

1 Reply

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

Answer by Statement · Oct 08, 2015 at 07:30 PM

Instead of incrementing it by one (one texture wrap), try incrementing it with Time.deltaTime. Incrementing it with 1 would not make any visible changes since it would perfectly jump to the next repeat.

 using UnityEngine;
 
 public class TestUV : MonoBehaviour
 {
     Vector2 currentOffset;
 
     void Update()
     {
         if (Input.GetKey(KeyCode.U))
         {
             currentOffset.y += Time.deltaTime;
             gameObject.GetComponent<Renderer>().material.mainTextureOffset = currentOffset;
         }
     }
 }

Works for me. Just remember to press U. The inspector does not update until you click somewhere on the inspector though.

  • Version 5.2.1f1 (44735ea161b3) Personal

  • Windows 8

  • Default material used ("Default-Material")

Comment
Add comment · Show 2 · 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 DeathByTouchy · Oct 08, 2015 at 09:16 PM 0
Share

Ah ha - thanks Statement! (And thanks Owen - I now understand what you meant by "You're also adding 1 to y, which is supposed to do nothing."

I'll give this a crack tonight after the day-job is over.

avatar image DeathByTouchy · Oct 09, 2015 at 01:31 AM 0
Share

Yep - that was it...offsetting by 1 was the mistake.

Thanks Statement and Owen!!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Tiling/Offset 0 Answers

Animated Texture doesn't begin at first frame 1 Answer

Is using texture offset with displacement shader possible? 0 Answers

Infintely scrolling texture ends?(only scrolls through once) 1 Answer

texture offset and timing (slideshow effect) 1 Answer


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