• 3D
  • How to add textEditor to my 3d scene attached to a 3d object and not the screen.

So I am trying to make a computer in my game with a functional desktop like this textEditor I am trying to put in. But when I put the scene into may main 3D scene and play the game it will be attached to the screen instead of on top of the 3D model 'monitor'. Like shown below:

Is there a way to get it to only show up on the 3D model like this?

Welcome to the forums @titanlock!

You could render your TextEdit node to a Viewport, and then use a Viewport texture to place it in 3D. The 2D in 3D demo on the Godot demo repository shows how this kind of thing can be done.

Oh this was exactly what I was looking for, thanks for the link. However when I follow what the example does I get this error: invalid set index 'albedo_texture" (on base: 'null instance') with value of type 'ViewportTexture'

So I am not sure what is wrong here. I read up that it might have something to do with the layout of my nodes but am not sure. I also had to put in the ViewportContainer to be able to get anywhere but noticed that the example project does not need this, so not sure what is happening at all lol.

Here is my tree:

Code:

extends Spatial

func _ready():
	var viewport = $ViewportContainer/Viewport
	viewport.set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)

	yield(get_tree(), "idle_frame")
	yield(get_tree(), "idle_frame")

	$KinematicBody/ViewportQuad.material_override.albedo_texture = viewport.get_texture()

Also I have found though if I manually put in the ViewportTexture in the Inspector it will load fine however the new viewport still shows up on the main camera instead of just under the ViewportContainer.

Based on the error, it seems like Godot isn't getting the material override (so its null). Does your Viewport quad have a override material set?

For the Viewport, you probably just need to make the Viewport container invisible, I think. Its been awhile since I've messed with 3D and 2D together, but I think its just a matter of changing the visibility and telling the Viewport to render when its visible.

You were correct on the Viewport needing to be invisible. But I am not sure what you mean by the material override being set. I do have a material set in there but I am not sure about how to specifically set an override for the material.

If you click the MeshInstance node you are using and go to the inspector, there should be a property called Material Override. The code is trying to get the material assigned to that property (ViewportQuad.material_override), so it will need to be set to a SpatialMaterial if there is not one already assigned.

4 days later

Oh yes I see it now, I would think that would have been somewhere under the material section but was in the Geometry section instead. Now everything works thanks a lot for the help!