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
4
Question by Tim Cooper · Jul 14, 2010 at 02:24 PM · shadereditorgraphicseditor-scripting

Allow shaders with 'time' variable to update in editor

Hi all,

I am have a shader that uses the _Time unity passed in value and I would like to see this material change and update in the editor (for example I might have a water texture and want to change settings without running the game to examine the changes).

I have tried attaching a script to the gameobject with the [ExecuteInEditMode] flag. but this only calls that script, it does not tick the shader time.

I have looked in the shader settings but could not find a way to do this.

I have also tried setting the global time variable like so:

var time = (float)EditorApplication.timeSinceStartup;   
Vector4 vTime = new Vector4( time / 20, time, time*2, time*3);
Shader.SetGlobalVector( "_Time", vTime );

and also setting it straight in shader, but it can not be found:

if( editorMaterial.HasProperty( "_Time" ) )
{
    Debug.Log( "has time" ); //This is never printed
}

Has anyone done this before? It seems like it should be something quite simple that I am missing.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bristar · Oct 11, 2011 at 08:43 PM

Instead of setting time to shader, create new parameter (like _Phase("_Phase", Float) = 0). And then set time value directly to this parameter.

 var time = Application.isEditor?(float)EditorApplication.timeSinceStartup:Time.time;
 Shader.SetFloat("_Phase", time );

or

 var time = Application.isEditor?(float)EditorApplication.timeSinceStartup:Time.time;
 Vector4 vTime = new Vector4( time / 20, time, time*2, time*3);
 Shader.SetVector("_Phase", time );
Comment
Add comment · Show 1 · 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 sooncat · Jun 14, 2012 at 01:42 AM 1
Share

This may help.

http://forum.unity3d.com/threads/61653-Get-_Time-from-shader-for-script

I agreed with @Ev_genus, define your own timervalue may be a better way.

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

1 Person is following this question.

avatar image

Related Questions

How to change editor highlighting behavior? 0 Answers

Shader works in Editor Mode, breaks when running. 2 Answers

Editor Script, Index Out of Range Exception after Play 1 Answer

Failed to initialize unity graphics - dxdiag is fine and opengl fails 1 Answer

Do I need to use SetDirty in my editors if I'm using SerializedProperties? 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