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 ovechkin1308 · Jun 07, 2011 at 08:48 PM · meshobjectmeshfilterfilter

Mesh Filter

I want to change the mesh of my object by script. I have different object that the player will can choose with a menu.

How I can change the mesh filter by script. Like if the player press B change the mesh filter by Ball 2 instead of ball 1

Comment
Add comment · Show 3
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 Chris D · Jun 09, 2011 at 10:11 PM 0
Share

@ovechkin1308 and @Retribution : try to keep your comments out of the answer area or attached to the answer that they're referencing. If you need to change the body of an answer, you can edit it.

At the moment this question's thread is very tough to follow and that is likely to hamper anyone else trying to understand what's going on.

avatar image Retribution · Jun 10, 2011 at 02:15 PM 0
Share

Sorry ChrisD. I'm new to Unity Answers, but I'll try to keep the posts cleaner in the future.

avatar image Chris D · Jun 10, 2011 at 03:12 PM 0
Share

No worries. Everyone was new at some point and, unfortunately, there isn't really a FAQ or guide to posting up for the new site yet :(

8 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Retribution · Jun 07, 2011 at 08:59 PM

You should be able to do something like this:

 var go : gameObject;
 go.GetComponent(MeshFilter).mesh = Resources.Load("<enter path here>");

Where 'go' is the gameObject you wish to access. You can use Resources.Load() and enter the path to the mesh in your project, or you could store the mesh in a variable that you could set through the inspector. For that, you would have something like:

 var go : gameObject;
 var meshToUse : MeshFilter;
 go.GetComponent(MeshFilter).mesh = meshToUse;

Where meshToUse is setup with a mesh in the inspector and go is the gameobject you want to access.

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 ovechkin1308 · Jun 08, 2011 at 01:46 PM

It's doesn't work. My principal script is on the sphere object that I want to choose the mesh filter. So I want that the player can choose the mesh filter he want.

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 Retribution · Jun 09, 2011 at 12:04 AM 0
Share

Forgot to include this in my post:

If you're copying this code into your project, it won't work right away. You'll have to change some of the code (like the path to your materials, or setup the $$anonymous$$eshToUse in your inspector) to get it to work.

If you're getting null reference errors for the 'meshToUse' variable, its because you will need to drag a $$anonymous$$eshFilter object into that variable under the script component.

avatar image
0

Answer by Retribution · Jun 09, 2011 at 12:02 AM

Ovechkin1308, do you get errors when you try this method? Or are you saying you can't accessing the object you want to change from your script location? Post some more details for me so I can try to understand your current issue.

To me, It sounds like you're saying: You have a menu that has selections of which mesh the player wants to use, and then you want to change the mesh on your sphere object when the player clicks one of the buttons. If this is the case, you should be able to do something like this:

 var targetSphere : gameObject;
 var meshToUse : MeshFilter;
 
 targetSphere = GameObject.Find("<your sphere's name>")
 
 // on button click
 targetSphere.GetComponent(MeshFilter).mesh = meshToUse;

If you're only having issues accessing your sphere object from your menu, you can use a method like this. By using GameObject.Find(), you can target your sphere object from your menu and change its MeshFilter based on what you select from the menu.

If this isn't your issue, please post more details as I've misunderstood your question.

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 ovechkin1308 · Jun 09, 2011 at 04:20 PM

So I will have a scene wich is the menu of the sphere choice. So it will have like 1 gui button for each type of sphere. when the player will click on the type of sphere he want the first level will load and I want that the sphere gameobject of my scene are of the right type.

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 Retribution · Jun 09, 2011 at 09:00 PM

Overchkin1308, I suggest looking at this part of the documentation for what you're doing: DontDestroyOnLoad. This allows you to save an object upon loading into the next scene, which will allow you to save your MeshFilter choice.

Attach your script that will be selecting your MeshFilter choice from your menu selection and use DontDestroyOnLoad to prevent this script from being destroyed upon loading into your next level. Once your next level as loaded, grab the MeshFilter you've stored in your script and assign it to the sphere in your level.

This should give you all the functionality you need to swap your MeshFilter out at the start of your first level. :)

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
  • 1
  • 2
  • ›

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity won't show my programatically created Mesh(A Simple Triangle) 2 Answers

Generated Mesh is partially rendered, but shown correctly in scene view 1 Answer

Combine multiple mesh entities to be exported as obj 1 Answer

OnMouseDown() with a Mesh Collider? 2 Answers

Query if MeshFilter is instantiated or shared? 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