+2 votes

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 []

Godot version 4.0.1
in Engine by (16 points)
edited by

1 Answer

–3 votes

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.

https://codabase.io/4480/resolving-array-type-mismatch-in-godot-4-0-1/

by (135 points)

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.

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...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.