• 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 musaranya · Feb 27, 2017 at 07:55 PM · prefab changing at runtime

Remap UVs and persist the changes

Hi,

I have a set of around 50 prefabs each one with its own LODs. I'm trying to remap the UVs of all the meshes to my atlas texture using a C# script in Unity because I don't want to make it one by one from Blender. I've done the code that makes de trick but I'm not able to persist the changes so when I close the Unity editor, next time I open it all the changes are lost.

I've tryed to execute this code at runtime on an instance of the prefab and Apply then the changes to update the prefab. Everything seems ok until I shut down the editor and open it again .

I've tryed to execute this code in Editor mode (not runtime) directly on the prefab (with an editor script and a button). Same as before: the remap seems ok but after shuting down Unity and opening it again all the changes are vanished.

Someone can give me an idea of what's going on?

Many thanks guys

PS: my remap code

  MeshFilter[] meshes = objecte.transform.GetComponentsInChildren<MeshFilter>();
  
 
         foreach (var m in meshes)
         {
            var mesh = m.sharedMesh;
             List<Vector2> uvs = new List<Vector2>();
             List<Vector2> newUvs = new List<Vector2>();
             mesh.GetUVs(0, uvs);
 
             for (int i = 0; i < uvs.Count; i++)
             {                
                 var v2 = new Vector2((uvs[i].x * factorEscalatX) + offsetX, (uvs[i].y * factorEscalatY) + offsetY);
                 newUvs.Add(v2);
             }
 
             mesh.SetUVs(0, newUvs);
         }
 
         //AssetDatabase.SaveAssets();  useless :(
        

Comment
Add comment · Show 2
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 MarshallN · Feb 27, 2017 at 11:21 PM 0
Share

Check out this asset - it's free on the asset store. Basically, what you're doing now is changing Unity's copy of the object, but not writing to the file. There are ways to do it manually, but if you're using .OBJ files, that asset is super useful - if you're not, there are paid assets for most other file types, or you can try your hand at writing your own or adapting the one I linked to work for different file types.

avatar image musaranya MarshallN · Feb 28, 2017 at 09:02 AM 0
Share

Hi, thanks for answering. I'm using FBX files but it doesn't matter, I will check this asset (It seems a bit more complex for what I need but I will parse and study it anyway). The thing that drives me crazy is that I read everywhere that working on the meshfilter.shared$$anonymous$$esh should update automatically the prefabs. It's not working for me don't know why...

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

64 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

Related Questions

how do i stop instantiate from changing a prefab 0 Answers

Dynamically Loading audio into a prefab and Instantiate in scene. 0 Answers

Unity 5 : Best way to initialize a UI panel coming from a prefab with many text fields ? 0 Answers

Prefabs won't change? 1 Answer

Multiple Prefab in Object Pool or One Prefab With Add Component 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges