Hi, thanks for taking your time to read this post.
I have encountered a small performance issue in my game project related to the MultiMeshInstance node
My project involves a Player scene that, whenever it jumps mid-air, creates a platform underneath the player.
The way it is done is:
MMI(MultiMeshInstance) stores all the meshes the Player may use.
Player sends signal to MMI -> MMI increases visible_instance_count -> MMI sets the transform of the last MeshInstance to Player's transform (creating the illusion that the Player creates the platform, while in fact MMI makes them visible and transforms them to the Player's location one by one)
My issue:
When this code is ran the very first time, there is a performance spike that lasts a single frame (the performance is top notch other than that.)
Upon inspecting the Profiler, I have found that when the code runs, the Idle Time is increased from 16~ ms to 96~ ms.
Upon inspection of the code, I have found that is occurs when Visible Instance Count increases from 0 to 1.
What I have tried:
I set Visible Instance Count to 1 instead, the Idle Time occurs when the scene loads instead of when the Player jumps for the first time, however this doesn't work for me since there will be a single platform in the middle of a scene where it shouldn't be, since all platforms are created on Player interaction.
Now, this is not an urgent issue by any means, however I'd still like any suggestions as to how I can remove this performance spike or mitigate it to the loading time of the scene.
In addition I would like to know why does this happen, even a generalized comment.
Here is the code:
extends MultiMeshInstance
onready var player = $'/root/World/Player/'
onready var block_spawn = $'/root/World/Player/BlockSpawn'
var spawn_position
var visible_count = 0
func _ready():
player.connect('spawn_called', self, 'spawn_called')
func spawn_called():
get_spawn_position()
position_mesh()
set_visible_instance_count()
spawn_collision()
func get_spawn_position():
spawn_position = block_spawn.global_transform
func position_mesh():
multimesh.set_instance_transform(visible_count, spawn_position)
func set_visible_instance_count():
visible_count += 1
multimesh.visible_instance_count = visible_count # this guy adds a ton of idle time, causes stutter at first run
func spawn_collision():
var collision_node = preload('res://BaseBlockCollision.tscn').instance()
collision_node.transform = spawn_position
add_child(collision_node)