Lag When spawn 3d Sphere

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MrHells

My problem comes when I try spawning a Scene that is a rigidbody with a 3d collider and a 3d mesh in a Spatial node inside de “world” node. It lags…

I saw some tutorials about pre loading your 2d particle materials, but I could not find such a tutorial for 3d models and it materials, I am new with godot, so I am trying to understand it, but alone I can’t.

I replied to a similar question recently. There’s a video of Bastian on the subject:

MrEliptik | 2021-03-21 10:23

I tried it, but it still hickup… Maybe I did wrong, but I tried so many times.

The code I use is

(in the player script)

var projectile = preload(“res://GameObjects/Entities/place_holder_shoot.tscn”)
onready var player_shoots = get_tree().get_root().get_node(“World/Player_shoots”)

the input function call the shoot function whenever mouse1 is pressed

func Shoot()
player_shoots.add_child_below_node(player_shoots, projectile.instance(), true) ( I also tries with player_shoots.add_child(projectile.instance()))
and also, I need to instanciate every time I shoot, because otherwise it will spawn only one at time.

MrHells | 2021-03-21 16:37

:bust_in_silhouette: Reply From: MrEliptik

The hiccup will always be present while Godot uses OpenGl. It’s due to the fact that openGL will compile the material shader of your objects the first time they are shown.

What you can do is render those material on a very small mesh. That way the mesh is not visible to the player. With that technique, you know exactly when the hiccup will happen, and you can maybe hide it behind a loading screen. This will avoid small hiccups the first time you instance a bullet or a particle for example.

In fact, did this happen every time I spawn the object in my scene…

I could repare it, I was using a sphere mesh from godot, and lowering the standtard 64 and 32 subdivisions I could get rid of the ridcup… But I am not sure if this issue can be a tuff problem in the future of my project

But your solution it’s what I did before.

MrHells | 2021-03-21 19:03