Garbage collection spikes, help please?

I’m getting regular spikes with garbage collection and it’s pointing to a script that draws a vectrosity line from the tip of a fishing rod model that is being bent using polymorpher.

Can anyone see anything that really stands out in my script that could be causing it? I honestly don’t have a clue. :frowning:

Here’s the code, it’s finding the vertex at the rod tip and drawing a line from it to another object.

using UnityEngine;
using System.Collections;
using Vectrosity;

public class polyMorpherSnapVertexVectrosity : MonoBehaviour {

	public PolyMorpher m_morpher;
	public int m_vertexID = 68;//this id match with rod model
	
	bool updateline = false;
	
	public VectorLine myLine;
	public Vector3 startPoint;
	public GameObject lineEnd;
	public Color colour;

	
	void LateUpdate () {
		if (updateline == true  lineEnd!=null){
		m_vertexID = Mathf.Clamp( m_vertexID, 0, m_morpher.m_mesh.vertexCount );		
		transform.position = m_morpher.transform.TransformPoint( m_morpher.m_mesh.vertices[m_vertexID] );
		myLine.points3[0] = transform.position; myLine.points3[1] = lineEnd.transform.position; myLine.Draw3D();
		}
		else{
			
		}
	}
	
	public void drawline (){
		myLine = VectorLine.SetLine3D (colour, transform.position, lineEnd.transform.position);
		updateline = true;
	}
	
	public void destroyline (){
		VectorLine.Destroy (ref myLine);
		updateline = false;
	}
}

Thanks

I assume that this may cause the spikes:

m_morpher.m_mesh.vertices[m_vertexID]

You are getting a new array in each frame! That means you are creating quite some junk.

Thanks, is there a way around that to get vertex positions?

Maybe you can get the vertices directly from the PolyMorpher without the need to create a new array. You may consider to contact the developer of PolyMorpher directly or read the documentation.

It was the developer who sent me that code, I just added the Vectrosity part to it.

I’ll get in touch with him again.

Thanks