- Home /
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];
}
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.
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.
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?
No, which is why i said data overriding. not method overriding