0 votes

Hey, guys. I'm trying to use a scene as a mesh from code for the Meshintance of a KB when running the game but nothing appears.
The funny part is when using CubeMesh the Cube appears on the screen.
Any ideas?

func _ready():


sprite = MeshInstance.new()
var mesh = load("res://assets/asset_test.tscn").instance()
# var mesh = CubeMesh.new()  THIS WORKS
sprite.set_mesh(mesh)


var material = SpatialMaterial.new();
material.albedo_color = Color.red

sprite.set_surface_material(0,material)

sprite.name = "Sprite"
add_child(sprite)
Godot version 3.2.3
in Engine by (15 points)

1 Answer

0 votes
Best answer

Simply put Mesh and PackedScene Resource are not compatible

External mesh types are of file extensions .obj, .tres, .mesh, .res

And compatible types are of CubeMesh, ArrayMesh, PrismMesh, QuadMesh, CylinderMesh, SphereMesh, CapsuleMesh, PointMesh, PlaneMesh

Basically if it doesn't end with Mesh it won't mesh with MeshInstance.mesh

The only way to achieve what you want is to dabble with ViewportTextures

by (4,472 points)
selected by

Thanks! Now I know what I was doing wrong :D

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 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 webmaster@godotengine.org with your username.