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 KitoCode · Mar 24, 2020 at 04:12 AM · mesharraylist

Data overriding itself?

I am having issues with my script I am trying to store in memory my 3d Mesh. But no matter, it always sets the mesh to its final result.

     private void BuildMeshList()
     {
         int uvTileX = (int)character.CurrentState.SpriteSheet.width / (int)character.CurrentState.SpriteSize.x;
         int uvTileY = (int)character.CurrentState.SpriteSheet.height / (int)character.CurrentState.SpriteSize.y;
 
         meshList = new List<List<Mesh>>();
         for (int y = 0; y < uvTileY; y++)
         {
             meshList.Add(new List<Mesh>());
             for (int x = 0; x < uvTileX; x++)
             {
                 Vector2Int position = new Vector2Int(x * character.CurrentState.SpriteSheet.width / uvTileX, ((uvTileY - 1) - y) * (character.CurrentState.SpriteSheet.height / uvTileY));
                 Vector2Int size = new Vector2Int(character.CurrentState.SpriteSheet.width / uvTileX, character.CurrentState.SpriteSheet.height / uvTileY);
 
                 meshList[y].Add(spriteMesh.DrawMesh3D(position, size));
             }
         }
     }


The code below is how i update the mesh.

     public void UpdateImage(Texture2D pTexture, Vector2Int pSpriteSize, int pFPS)
     {
         if (spriteMesh == null)
             return;
 
         if(spriteMesh.texture != pTexture)
             spriteMesh.texture = pTexture;
 
         int uvTileX = (int)pTexture.width / (int)pSpriteSize.x;
         int uvTileY = (int)pTexture.height / (int)pSpriteSize.y;
 
         // Calculate index based on FPS and our timeScale
         int _index = (int)(Time.timeSinceLevelLoad * pFPS) % (pSpriteSize.x * pSpriteSize.y);
 
         // split into horizontal and vertical index
         int uIndex = 0;
 
         //This will create an instant character image switch when the player rotates the player around the player.  
         // There used to be a noticable pause in changing the image
         if (prevIndex == _index)
             return;
 
         //Are we animating?  If so then update the uIndex
         //if (IsAnimating == true) 
             uIndex = _index % uvTileX;
 
         prevIndex = _index;
         renderer.material.mainTexture = pTexture;
         
         meshFilter.mesh=null;
         meshFilter.mesh = meshList[(uvTileY - 1) - (int)currentDirection][uIndex];
     }




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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Mar 24, 2020 at 05:30 AM

What does the "spriteMesh.DrawMesh3D" method do? Does it actually create a new Mesh instance every time it is called? If not (i.e. if it reuses and returns the same mesh object) you would store a reference to the same mesh in your list. So the relevant information seems to be missing here.

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 KitoCode · Mar 24, 2020 at 04:27 PM 0
Share

that was it, thanks. In the spritemesh class i had a single mesh being created in its constructor and reusing that mesh. I assumed when assigned to a new value, it would create an instance at that time, apparently it does not.

avatar image
0

Answer by Lester2350 · Mar 24, 2020 at 05:49 AM

Missing information has been found in you question, can not understand what you want to say? Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific talktosonic implementation of a method that is already provided by one of its superclasses or parent classes. are you talking about this?

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 KitoCode · Mar 24, 2020 at 04:25 PM 0
Share

No, which is why i said data overriding. not method overriding

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

156 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 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 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

A node in a childnode? 1 Answer

how to assign mesh.vertices ToList linq extension 1 Answer

Array of Colors not working. 2 Answers

Is it possible to convert c# generic List<> to normal arrays? 1 Answer

List of bools assigned to each Gameobject in List/Array 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