Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by skwr · May 03, 2019 at 05:55 AM · shadersspritesproblem during runtimedisappear

Changing sprite renderer material cause sprite disappear

I created my own shader using shader graph to cover my specific problem. I need to create some kind of FOV for my main camera. Shader take global position of the camera and offset global position of mask on material assigned to multiple sprites. That let me insert few sprites on scene and mask will always be in same global position as camera. alt text That works just fine, and I am happy with the result, but... Now I need to have couple of objects with this material always "visible". I was trying a lot of ways to do this, but always something goes wrong. Whatever I tried it finished as sprite disappear.

1) I was trying to use Branch node in shader graph to turn on and off mask, based on property changed by C# script (MaterialPropertyBlock) for single object. Sprite disappear whenever I want to switch its state.

2) Next time I tried change radius property via C#, same problem, but if I am passing Camera.main.transform.localScale.x to this property it is OK, and i can adjust radius using camera scale.

3) Finally, i was trying to just switch material on single object via script...disappear. It is disappearing even I manualy switch material on runtime.

alt text

There are two more things to say:

All this sprites are instantiate by some kind of generator, maybe problem is placed there, but it is just normal instantiate. I wrote small script to instantiate same prefab, and this one works fine. I can change material manualy and it works.

Second one, I find out that when I am changing material on sprite or properties, sprites wireframe is changing. If normal sprite is like two trinagles, that after change material it is disappear. Only if i select object, i can see rectangle outline around it.

I am going to go through my generator scripts tomorow, maybe i`ll find something, but it is looking weird.

Apologize my english, if something isn`t understandable i can try to give you more context.

disappear.png (121.1 kB)
shader.png (133.6 kB)
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 skwr · May 05, 2019 at 05:26 PM

I rebuild my generator to Instantiate every object from same place in code, and it seems to fix problem.

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 skwr · May 10, 2019 at 03:15 PM 0
Share

edit: it isn`t fix problem, but I found what exactly cause it. Everything works fine until I change size of object (transform.localSize) from script. First I thought that is problem, but it isn`t. I am just stupid and set localSize as new Vector3(sizeX, sizeY, 0). Zero on Z axis cause disappearing my object from scene when i pass values to shader parameters.

I didn`t work on Unity for long time, past in time every 2D object has 0 depth in my small projects and everything works fine. Looks like something change ;)

At least I rebuild my generator, and now it works better, faster and so on. Nothing bad happend.

Hope that it can help someone in future.

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

116 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

Related Questions

Why is my sprite disappearing when I make a new material and add the Sprites-Default shader? 1 Answer

Limit Amount of Light Applied to Sprite 0 Answers

Problem to solve Z-Fighting with Offset shader, how can I do it works? 2 Answers

Sprites not working with Depth of Field Post Processing 0 Answers

How to make transparent shader (2D)? 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