Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to change a materials bool in c#?

Discussion in 'Scripting' started by LittleRainGames, Mar 19, 2017.

  1. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    There is SetFloat, SetVector, but where is SetBool?

    Also, what about Int2, 3, and 4?
    Here is a substance with Int2, but I'm not sure how to change with script.

    And last question, would float 3 in a substance be a Vector3, or int[3]?

     
  2. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    There is no SetBool. Boolean values in shaders are integers of either value 0 (false) or 1 (true). So material.SetInt( "_KeepRatio", 1 ) would set the "Keep ratio" toggle to true. :)
     
    steryo, wangsitan, Coccho and 6 others like this.
  3. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    Ahh ok thanks, I thought it might be something like that. As for Int2, how would I change brickcount x?
     
  4. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    You're welcome!
    As for Int2 I have no clue to be honest so I must leave it for someone else to answer. .__.'
     
  5. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    No worries haha. You don't by chance know how to change substance Input Parameters by script, or can you?
     
  6. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    Nope. The most advanced I've done regarding shaders is "toggles", needless to say I'm far from beeing good at it.
    I did a quick search on google though, could this help? https://docs.unity3d.com/ScriptReference/ProceduralMaterial.html
     
  7. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    Haha yeah actually. I was just reading that and came to post my findings. Thanks again.
    I don't know why I couldn't find it earlier, looked here and then was looking on SD forums.
     
    Kona likes this.
  8. tcshaw91

    tcshaw91

    Joined:
    Jul 26, 2018
    Posts:
    9
    For anyone recently searching for this. I found this issue as well where i downloaded an effects shader and was trying to change certain values and while the floats and textures updated, the bools did not. Firstly, the bools were Floats and not ints (which i thought was weird) but secondly the bools labelled "Toggle" with a ("string") afterward apparently require the "EnableKeyword()" and "DisableKeyword()" to toggle them and the "keyword" is the string in the parentheses after "Toggle". (I think there's also a method to print all the keyword, or you can view them in debug mode). Even when i changed the float value between 0 and 1, it wasn't until i used the Enable/Disable Keyword method that I was able to see any change.
     
  9. steryo

    steryo

    Joined:
    Feb 7, 2017
    Posts:
    8
    Would've never figure out by myself, thanks a lot