How do I correctly initialize an exported custom typed array inside a and of a Resource type?

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

My code in short is

extends Resource
class_name Blueprint

@export var recipe: Array[BlueprintRecipeItem] = []

func _init(p_recipe = []):
	recipe = p_recipe

but with this I get an error:

Trying to assign an array of type "Array" to a variable of type "Array[BlueprintRecipeItem]".

I also tried [null] instead of []

:bust_in_silhouette: Reply From: codabase

Hi there! Your post inspired me to write an article on the topic. Here is what I believe will solve your problem, please let me know if you have feedback for it or if this solves it! Good luck and I hope I’ve helped.

Did you actually try that out?
Because I specifically said I also tried [] and still got the error, actually it was the first thing I tried.

jonathanfk | 2023-03-22 15:40

Don’t spam your content farm blog here… These kinds of blogs are bad enough clogging up all the Google results, last thing we need is them clogging up the Godot Q&A…

einsteinx2 | 2023-05-07 15:18