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
0
Question by DavidM · Nov 06, 2010 at 01:53 AM · mesheditor-scriptingmeshfilter

Editing tools issues

I have been creating some editing tools to aid in indoor level creating within Unity.

I have a Script called CubeInfo which has a single variable called cubeSize, a Vector3.

I made a Custom Editor class called CubeEditor which has an OnInspectorGUI method which allows editing the cubeSize.

If the GUI.changed variable is set, I call a Rebuild() method on the CubeInfo object.

The problem is with modifying meshes.
I cannot just grab the MeshFilter.mesh variable, because the editor yells at me to use sharedMesh.

If I use sharedMesh, I end up changing the mesh of any other objects I duplicated ( Ctrl-D ).

I can create a Mesh each time, but this is quite wasteful as a new one is generated each time I change cubeSize in the GUI. Basically there is no way from script to know when to modify a mesh and when to create a new one.

It seems quite odd that the Editor has no way to give you a modifiable copy of the Mesh like the .mesh variable does at runtime.

-DavidM

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 kjems 1 · Nov 09, 2010 at 12:03 PM

I tried going down that road but it got messy and ended up making the custom tools using scales instead. I do however know how to get you past the first few humps in the road:

Making a new shared mesh instance:

string meshName = meshFilter.sharedMesh.name;
meshFilter.sharedMesh = Object.Instantiate(meshFilter.sharedMesh) as Mesh;
meshFilter.sharedMesh.name = meshName; 

Is the mesh stored persistently somewhere in the AssetDatabase?:

EditorUtility.IsPersistent(meshFilter.sharedMesh)

If it is not persistent, it is because you already made a new instance and the mesh is floating in the scene.

Saving an instance of a mesh back to the assetdatabase by adding to an existing object:

AssetDatabase.AddObjectToAsset(meshFilter.sharedMesh,<Some asset in the DB>);

..or by creating a new object:

AssetDatabase.CreateAsset(meshFilter.sharedMesh, "Assets/Meshes/" + meshFilter.sharedMesh.name + ".asset");

Things start to get really messy when your newly created mesh instance is stored inside a prefab and that prefab is used in another scene, because the mesh instance was stored in the scene and not the prefab. You can add your mesh to the prefab using the AddObjectToAsset but there are no API functions to remove it again or move it to another object. In fact you are not even allowed to save it again to a new object using AddObjectToAsset, so it is just stuck in the prefab.

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 DavidM 1 · Nov 09, 2010 at 05:42 PM 0
Share

Thanks for the information.

I am not interested in making prefabs, just in building level architecture ($$anonymous$$ost rooms vary somewhat compared to other rooms). The real issue is just deter$$anonymous$$ing if a mesh is shared amongst other GameObjects.

It would be easy if there was a refCount variable on $$anonymous$$esh. Reference counting works fine when there is no chance of circular references, and it would make these sort of tools easier.

avatar image kjems 1 · Nov 09, 2010 at 10:33 PM 0
Share

One thing that might work in your case is to make a new $$anonymous$$esh in the OnEnable() function of the custom editor class. It is not as elegant as a solution using some sort of refCount, but in practice it might work out fine.

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

No one has followed this question yet.

Related Questions

Weird issue with mesh.Clear() 1 Answer

Instantiate within boundaries of Mesh shape 2 Answers

Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer

Can I store a mesh in a class variable ? 4 Answers

Im reading a .obj file and converting it to a mesh (doesnt work) 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