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
1
Question by Olie · Mar 26, 2010 at 03:50 AM · errorrendererfade

How to fade out an object with no renderer (and how is that even possible?!)

Noob here, cribbing from other scripts, I see that I can do...

target.renderer.material.color.a -= Time.deltaTime/fadeDuration;

to fade out an object. And, elsewhere in the docs, I see that EVERYTHING YOU SEE ON SCREEN has a renderer that you can enable = true/false to show/hide it. Ok... but the above line gives me "renderer is not a component of GameObject" error. So, being resourceful, I think...

var target : GameObject; var targetRenderer : Renderer;

function Start() { targetRenderer = target.GetComponent(Renderer); if (targetRenderer == null) targetRenderer = target.GetComponentInChildren(Renderer); }

function Update() { if (targetRenderer.material.color.a > 0) targetRenderer.material.color.a -= Time.deltaTime/fadeDuration; }

but then I get "trying to access Renderer on GameObject when there is none." What gives? What am I missing?! If it's on-screen, it's got to have a renderer, right?!

Thanks!

P.S. All I really want to do is make my object fade out before removing him from the scene, like in TonyD's script, here.

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
3
Best Answer

Answer by Eric5h5 · Mar 26, 2010 at 05:20 AM

The first line of code you wrote is fine, but you haven't given enough info about how you're defining variables. For example, this works with no issues, assuming the target object actually has a renderer:

var target : GameObject;

function Update () { target.renderer.material.color.a -= Time.deltaTime/fadeDuration; }

But a GameObject doesn't necessarily have a renderer. The only required component is a Transform. If you're trying to access a renderer component of a child GameObject where no renderer component exists, then you will get the error message you quoted.

Comment
Add comment · Show 3 · 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 Olie · Mar 26, 2010 at 02:01 PM 0
Share

Ok, but, as I understand the docs, if I can see something on the screen, it's got a renderer, right? So if I check the original gameObject's render and it's null, I should check the children, right? And, if it's on-screen, one of those two things should have a renderer, right?! In my test case, the object I'm using is the copperDeadPrefab from the 3d-platformer tutorial.

avatar image Olie · Mar 26, 2010 at 02:05 PM 0
Share

I've updated the questions's code sample to be more explicit about what I'm trying-and-failing. The target GameObject is an object I can see in the scene. The error message appears to be telling me that it doesn't have a renderer, which is counter-intuitive to me. I'm trying to figure out if I mis-understand the error msg or if I misunderstand "everything you see has a renderer" (or both :D)

avatar image Eric5h5 · Mar 26, 2010 at 06:07 PM 1
Share

@Olie: if you get a message saying an object doesn't have a renderer, then the particular object you are referencing does not have a renderer. So you may not be accessing the object you intended to access. BTW, an object can be visible without a renderer, such as a GUITexture. The only way to tell for sure is to look at the object and see if it has a renderer component.

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

Changing two different objects renderer colour 1 Answer

Help with changing spririterenderer's sprite 2 Answers

Why isn't this mesh not appearing properly? 0 Answers

Why do obejcts fade when farther from the camera when using URP? 1 Answer

Instantiating Material Error? 0 Answers


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