Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ina · Dec 26, 2010 at 01:34 PM · destroyruntimelinerendereraddcomponentclear

Destroying a LineRenderer component and then adding it again at runtime

I have a global var lineRenderer:LineRenderer that is:

  • initiated in Start() via lineRenderer = gameObject.AddComponent(LineRenderer);
  • has its setPosition() populated with a bunch of coordinates - so it appears like a "drawn line" on a whiteboard

And then I want to erase the board - presumably, the way to do that is Destroy() ... so I tried Destroy(lineRenderer);

When I attempt to reinitiate it with lineRenderer = gameObject.AddComponent(LineRenderer);, I get errors like: "Can't add component 'Line Renderer' to lRenderer (name of game object) because such a component is already added to the game object!"

Subsequent lineRenderer.property assign's yield errors like: "Object reference not set to an instance of an object"

So, long description short, how do you ERASE the line from a lineRenderer, so that you can repopulate its setPosition? (Not sure if destroy is the right word..)

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Loius · Dec 26, 2010 at 03:03 PM

By reading the documentation, it looks like you want

GetComponent(LineRenderer).SetVertexCount(0)

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 ina · Dec 26, 2010 at 03:40 PM 0
Share

No. Error still occurs. I had that in there before, referenced as lineRenderer.SetVertexCount(0) -- to be sure, I tried GetComponent(LineRenderer).SetVertexCount(0); - same error still occurs

avatar image
0

Answer by Nomad the Grey · Mar 01, 2011 at 06:22 PM

Although I realize that I am replying to this post a couple of months later than necessary, perhaps I can help somebody anyway. This error exists in ordinary .NET apps. When I see this error, I fix the problem by inserting code similar to:

lineRender = new LineRenderer();

Hope this helps.

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

Answer by RyanZimmerman87 · Mar 09, 2013 at 02:22 AM

 public LineRenderer lineRenderer;
 
 Start()
 {
 lineRenderer = gameObject.GetComponent<LineRenderer>();
 }
 
 Update()
 {
 if (your desired conditions)
 {
 lineRenderer.SetVertexCount(0);
 }

That seems to be working for me, hope this helps.

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

Answer by liamrasoull · Apr 28 at 06:49 PM

you can use lineRenderer.positionCount = 0;

lineRenderer.SetVertexCount(0); is outdated.

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

2 People are following this question.

avatar image avatar image

Related Questions

Clearing a LineRenderer Whiteboard, so that you can start drawing again 1 Answer

Destroy the first instanced prefab while still being able to generate more prefab's later 1 Answer

Export objects to a .3DS file at runtime 1 Answer

Is there such thing as a recommended Component cap? 0 Answers

AddComponent performance 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