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
2
Question by xmalthex · Jan 08, 2013 at 11:16 AM · texturematerialchangeflickering

Flickering materials/textures when changed by script

I am doing a serious game for a research project and I've run into some problems I can't get my head around.

What I'm trying to make is a display for an elevator that changes between different numbers over time to make it appear as the elevator is moving. I have tried different approaches, switching out textures, materials and even objects to make this display but they all end up the same, a seemingly random flickering between the different numbers.

I am new to scripting but this is what I've been trying to use. The script is supposed to change the material of the specified gameobject, wait for specified time, change the material again and so on.

 var timeBetweenFloors : float = 5;
 
 private var idDisplay : GameObject;
 
 function Awake () {    
     idDisplay = GameObject.Find('display');
 }
 
 function Update () {
     ElevatorRide();
 }
 
 function ElevatorRide () {
     idDisplay.gameObject.renderer.material = Resources.Load("display15") as Material;
     yield WaitForSeconds (timeBetweenFloors);
     idDisplay.gameObject.renderer.material = Resources.Load("display14") as Material;
     yield WaitForSeconds (timeBetweenFloors);
     idDisplay.gameObject.renderer.material = Resources.Load("display13") as Material;
     yield WaitForSeconds (timeBetweenFloors);
     idDisplay.gameObject.renderer.material = Resources.Load("display12") as Material;
 }

When I run the game this first changes the material of the display to the correct one, "display15", but on the next step it just begins to flicker between all of the mentioned materials in the code at a seemingly random rate.

The result is the same when I use .renderer.material.maintexture to switch out the texture instead. I also tried making a duplicate of the display object for each number and applied different textures to them and switched the rendering of these objects on and off as below but with the same flickering result.

 floor16.gameObject.renderer.enabled = false;
 floor15.gameObject.renderer.enabled = true;
 yield WaitForSeconds (TimeBetweenFloors);
 floor15.gameObject.renderer.enabled = false;
 floor14.gameObject.renderer.enabled = true;
 yield WaitForSeconds (TimeBetweenFloors);
 ...


Is there something I have done completely wrong in my code? Are the previously used materials/textures supposed to remain visible even after they are changed out?

Is there a better approach to make a display that changes texture/material with specified time intervals?

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 Alpha-16 · Dec 21, 2018 at 04:04 PM 0
Share

I'm running the same issue. Did you found the solution ?

avatar image jimmycrazyskills Alpha-16 · Dec 21, 2018 at 06:59 PM 0
Share

Hey mate, I've added an answer not sure if it helps you :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jimmycrazyskills · Dec 21, 2018 at 06:51 PM

Hi mate, I'm not completely sure but I think it might be to do with the order of execution.
Order Of Execution:

  1. Elevator Ride is called from Update function (takes a little bit of time).

  2. Material is changed to display15 (takes a little bit of time).

  3. WaitForSecondsIsCalled (takes a little bit of time).

  4. Depending on how much time it's taken to execute these lines, we might get Another Update call come through.

  5. Now ElevatorRide is called again, whilst the previous call is still happening, so you will lose which order the materials change in.

    Below is a picture of what I'm trying to explain (the numbers being the order in which each line is executed, each colour represents a new call to ElevatorRide):

alt text


My main point here is that the ElevatorRide function doesn't necessarily complete before a new ElevatorRide starts so this is why you are seeing a 'Random' order of materials.
Hope this helped explain abit :)


executionorder.png (26.8 kB)
Comment
Add comment · 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

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

10 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

Related Questions

How to switch texture of several 3D objects on GUI buttons click? 1 Answer

Best option to change texture/material.. 0 Answers

How to create a GUI button to change a character's texture in real-time? 2 Answers

Cost of changing texture 0 Answers

Changing GameObject texture? 4 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