We go the following route to apply a distorted camera effect to our game:
We save scales and positions in the PreCull method of objects affected.
Change their values.
And restore them in the PostRender method.
This works flawlessly in Unity 3.5.7, but since our switch to Unity 4 this very method seems to
slow performance significantly down - 900 frames per second down to 60 on a PC!! That obviously pretty much
renders the game unplayable on mobile devices.
Could any of you fellow developers please give us a hint on why this is happening and how to fix this
issue.
Kind Regards
PS: It seems that WRITING positions/scales is causing the lag.
Thanks for your reply. Upon further research we narrowed the problem down to scaling.
Uniformly scaling an object to another value than 1 on every update brings the framerate down by a factor of 10.
I can’t test currently, but we believe doing so in Unity 3 wasn’t that expensive.
We did a simple test scene with 2 spheres and a plane.
The following component is to be added to the camera:
using UnityEngine;
using System.Collections;
public class ScaleChangeCamera : MonoBehaviour {
public bool ScalingOn = true;
public float m_ScaleMultiplier = 0.5f;
private ScaleMe[] m_ScaleMes;
void Start () {
m_ScaleMes = (ScaleMe []) FindSceneObjectsOfType(typeof(ScaleMe));
}
void Update () {
if (!ScalingOn) return;
foreach (ScaleMe sm in m_ScaleMes) {
sm.transform.localScale = m_ScaleMultiplier * Vector3.one;
}
}
}
And the component on objects to scale:
using UnityEngine;
using System.Collections;
public class ScaleMe : MonoBehaviour {
}