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
1
Question by BeastDevBoi · Nov 24, 2020 at 12:07 PM · shadermaterial

One outline material for multiple objects?

Hello! Quick question- I am working on a 2D pixel topdown rpg, and I have made a simple outline shader, with a material, and am using it on my sign object. Morse specifically, when you hover your mouse over it, an outline appears. However, currently, when I hover over ONE sign, ALL OF THEM get an outline. I achieve this by having a OnMouseOver() script that sets the Material's outline thickness variable. So: is there a way for the material to have separate variables of every object or do I have to make multiple materials that use that shader? Thanks!

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

2 Replies

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

Answer by BeastDevBoi · Nov 24, 2020 at 12:44 PM

 **public class SignHandler : MonoBehaviour
 {
     public DInteractible din;
     public DialogHandler dih;
     public Material outl;
     void Update()
     {
     }
     public void OnMouseOver()
     {
         bool isdialogue = FindObjectOfType<DialogHandler>().dialoguestarted;
         //this is a bolean that blocks the dialogue script from starting if a dialog has already started
         this.outl.SetVector("Vector2_AD1BF9C3", new Vector2(1, 0));
         //outl is my outline material, and Vector2_AD1BF9C3 is the the outline thickness vector
         if (Input.GetKeyDown(KeyCode.Mouse0)&&!isdialogue) //i use this to start a dialogue
         {
             din.TriggerDialogue();
         }
     }
     public void OnMouseExit()
     {
             this.outl.SetVector("Vector2_AD1BF9C3", new Vector2(0, 0));
     }
 }**

Sure, here you go! I am also fairly new in unity, so please be as direct as you can with what I should use. Thanks!

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 Envans · Nov 24, 2020 at 12:50 PM 0
Share

Ok I see what you are doing wrong let me quickly explain it so you can understand it too.

From what I see you are dragging the material from the asset to the material outL field in the inspector, this changes the variables for the "master" material thus changing the variables for all sprites with the material.

what you should do instead of have a public material is this

  **public class SignHandler : $$anonymous$$onoBehaviour
  {
      public DInteractible din;
      public DialogHandler dih;
      private $$anonymous$$aterial outl;
 
     private void Start(){
         outl = GetComponent<SpriteRenderer>().material;
    }
 
      void Update()
      {
      }
      public void On$$anonymous$$ouseOver()
      {
          bool isdialogue = FindObjectOfType<DialogHandler>().dialoguestarted;
          //this is a bolean that blocks the dialogue script from starting if a dialog has already started
          this.outl.SetVector("Vector2_AD1BF9C3", new Vector2(1, 0));
          //outl is my outline material, and Vector2_AD1BF9C3 is the the outline thickness vector
          if (Input.GetKeyDown(KeyCode.$$anonymous$$ouse0)&&!isdialogue) //i use this to start a dialogue
          {
              din.TriggerDialogue();
          }
      }
      public void On$$anonymous$$ouseExit()
      {
              this.outl.SetVector("Vector2_AD1BF9C3", new Vector2(0, 0));
      }
  }**

so you make the material private and you get it from the SpriteRenderer of the sprite, then when you make change the changes only apply to that sprites spriteRenderer and not all sprites with the material. If you have any more question feel free to ask!

avatar image BeastDevBoi Envans · Nov 24, 2020 at 01:03 PM 1
Share

WOW! Thanks SO $$anonymous$$UCH for how fast and direct you answered! I even understood what you are talking about, which I don't on most of the forums I've been. I HAVE heard that making everything public is a bad practice, but I found stuff is usually harder to work with if I don't. I totally forgot what component even USED the material, I kinda feel embarrassed now... Again, thanks and I will stick around if I need anything else.

avatar image
0

Answer by Envans · Nov 24, 2020 at 12:27 PM

When changing a material the result you would normally get is just changing that objects material variable not all objects that have that material. Maybe you can post the OnMouseOver script so we can take a look and help you further?

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

226 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing Eye Colour (Colour only non-white parts of a texture?) 2 Answers

GL - Shader not working in Android 1 Answer

Control materials opacity. 2 Answers

How can i get my quad to only render my texture without stretching it? 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