Why using & before strings?

Godot Version

4.2.1

Question

I am a beginner and have only a small question, but it drives me nuts:
I often see in other persons code a & char before any strings.
For example:

if not body.is_in_group(&“player”):

get_script().set_meta(&“singleton”, self)

Why are they using it? I cannot find the answer and see no benefits. It works like the same without the &.
Can please someone explain?

& is the StringName shorthand constructor

1 Like

When you put the & sign before a string you make it a type StringName

This is sometimes more performant.
Two strings with the same name will be the same object when using StringName types and comparing strings is way faster because of that.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.