Shader Graph and C# Interaction! Set Properties from Scripts! ✔️ 2020.3 | Unity Game Dev Tutorial

preview_player
Показать описание
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3

Oftentimes, it's useful to set shader properties from a C# script. In this video, I show how to set property values on a shader created in the URP shader graph. In the process, I create a system that draws colored ripples wherever you click on a mesh.

👋 Subscribe for weekly game development videos!

👑 Join my Patreon for extra influence over topics, early access to videos, and downloadable project files!

🔗 Check out my website for a searchable list of tutorials!

💬 Video transcript

📚 Reference scripts

⏲️ Timestamps:
0:00 Intro
0:57 Project setup
1:47 The graph
3:40 The initial script
5:04 Randomizing colors
5:58 Instantiate material
6:33 Optimizations
7:35 Wrap up and credits

🎖️ Credits and references:

#GameDev #IndieDev #Unity
Рекомендации по теме
Комментарии
Автор

BRO I WAS LITERALLY LIKE 6 HOURS TRYING TO FIGURE OUT WHY DOESN´T THE FLOAT ISN´T RETURNING ANYTHING AND IT WAS JUST BECAUSE OF THE REFERENCES, YOU SAVE ME I FUCKING LOVE YOU SO MUCH

benjaminborja
Автор

Wow. Simple to follow and so powerful for my app development thanks!

ZacharyAghaizu
Автор

Instead of copying the material, you could use a material property block. That has the benefit of being able to set the property values differently per renderer or mesh without having to create new materials for each one. However, it also has the cost of reducing batching. There are always tradeoffs.

GamesEngineer
Автор

Thanks a lot I was wondering how to link between shaders and scripts. Plus the optimization tip at the end was also very helpful.

subhadas
Автор

Your content is good enough to take over Brackeys' throne.

ThomasChen-urgt
Автор

Thank You!
This is excellently done. Clear. Concise. All the details.

MatthewAWinston
Автор

my man ned these tutorials are amazing

leemiller
Автор

3:29 -> Back in the scene E-DI-TOR

He became a robot for a moment! Lol

paufenollosa
Автор

LOOKS AWESOME!!! Keep up the good work buddy, liked and subscribed! <3

shivanshchanana
Автор

Your videos are really great! Short and to the point.

Mad
Автор

Thank you for this useful video. We can do the same using animation. I found that doing this with animation is more stable and less complecated.

awwad
Автор

REMEMBER: In the Graph Insperctor, add your active target (URP, HDRP or Build-in). If it is not set correctly, you will have a pink material.

paufenollosa
Автор

Hey not sure if I will explain myself correctly but if I understood this right, before working in a shader you need to understand what type of information you need to feed to it (kinda obvious right?) like for example, you knew you have to define the distance and you literally apply a physics concept of "Time . velocity = Distance" you already knew you needed that information. My question is... how can you tell what type of information you need to feed the shader? Is this something that comes up by practice or is there another type of documentation other than the Unity manual? And if it's just becose of practice and experience how do you come up with an effect from scratch without knowing what type of information you need to feed in the shader?
Is this just a matter of playing with the options until you come up with something interesting, or these types of things are something calculated and planned ahead?

juancarloshortaflores
Автор

Thanks for video. I understood how interact with material from component, don't get it before.

ludenusport
Автор

I have Problem on that, in this color is auto filling without i am touching. what should i do help me.

argonprit
Автор

Really cool intro project to shadergraph, tanks a lot!
What about a shader that hides/reveals items for your next video? 🤷‍♂️😀

fulongfromthegrave
Автор

Ned, I have a question, is there a way that we can set a 3d meshes material color automatically depending on this terrain/surface color? For example if there is a toon ramp blend effect on the surface, i want the objects laying on the surface to change its color from dark, grey or white depending on its surface color which is created by the toon light effect

nyan
Автор

Hi, thank you so much. I'm stuck trying to change the properties of multiple materials. For instance in your example at the end you have lots of spheres all changing at the same time. I'm looking to do that but for a different project. Do I have to loop through all the materials? Is there a way to get all the objects share the same material (do I have to change this at runtime?) or can I set a Shader.SetGlobalFloat() - which doesn't seem to work for me yet. Is there a way to change multiple materials all using the same shader inside the Update()

Confused and stuck!

AtmosMr
Автор

Thanks for this clear tutorial! Helps a lot! I’m curious, how would you make the ripple a square getting bigger around the mesh, instead of being a circle getting bigger from the starting point?

elmidiachi
Автор

I've a shader with a variable called Fill. When I use material.SetFloat("_Fill", value) doesn't work I don't know why.
But searching in the script generated by the Shader Graphs, that "Fill " variable is designed with So when I use material.SetFloat("Vector1_52c...blablabla", value) works.
If I change this Vector1_52c8blablabla" to _Fill neither works. Do you know why? I tried folloing the video steps but I just can make it works this way.

HehasChinese
visit shbcf.ru