Is it possible to create a empty group, editor or by code?

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

I’m setting the camera for a topdown 3d game and i want to lerp FOV according chasing enemies in the most performance-wise way.

I thought about creating a group with chasing enemies for that, but at the beginning group will be empty. If i try from editor, empty groups are automatically deleted and i don’t know if a group can be created at runtime by code.

Other way is create an array, but i don’t know if it would be quite expensive to iterate in.

:bust_in_silhouette: Reply From: umma

How about you use an animation player node

var chasing_enemies = false

Func _process(_delta):
  if chasing_enemies == true:
    $animation_player.play("fov_outward)

Func _on_animation_player_finished(anim):
  chasing_enemies == false
#create a function on the animation player when it's finished

Hi! Thanks for your answer.

At last I did by array, as I wanted enemy nodes position to lerp fov based on distance to player.

What I’ve done:

As I wanted camera logic autocontent, enemies are in a general group, called “enemies”.
Once an enemy chase player, emits signal.

In camera logic, I connect the enemy signal by iterating in all enemies group. It’s no heavy as is done just once on ready().

After, each time signal is emitted, enemy is recorded in an array. With it, I just have to iterate to get closest and farest enemy from player, that was my concern, but is not affecting performance, and use these data to play with camera properties.

Anyway if in future I have to optimize more (quite possible), tweaking your proposal could be a simpler but also effective solution.

heavyathan | 2022-06-08 17:59