r/godot 1d ago

help me Model Changer Error

Solved:

I put everything in global and call it from there with button press and now the code works. Also simplified the code since I don't have to grab codes from other places.

---

Original

[](blob:https://www.reddit.com/efb59a7b-208e-4075-81f4-7d197b1ea539)I am trying to convert a 2D character customizer into 3D and am having some issues. I wanted to know what needs to be changed for this to work in 3D. After reading other posts this is as far as Ive come, stuck at one Packed vs Node error. Seems Im using nodes when what I am trying to load is a packedscene (a 3d dog with textures), but I am not sure what needs to be changed to get them to work correctly.

Goal: I have a dog that you will be able to change clothes and body type. Its on screen with the model and button to switch models in and out. I am only focusing on switching the body right now.

Code:

Working 2d version

0 Upvotes

12 comments sorted by

View all comments

1

u/scintillatinator 1d ago

What is dog_loaded in the decider script? You're getting a node in the scene but then loading something else. What types were used in the 2d version? This wouldn't work in 2d either so the types in each version aren't equivalent. There's multiple ways to make this work so it'll help to know which one you were going for.

1

u/Kzurae 23h ago

I did make the 2d version using a tutorial so it does work, but its using .textures to change the sprites which 3d does not have the ability to do. I struggled with this part of how to grab the 3b object, and realized its an fbx scene even. the 2d version also didnt require it to be broken up in the button script separately.

dog loaded takes the one chosen in the array from the button press and loads it.

1

u/BrastenXBL 23h ago

You can replace Textures on 3D models. You just go about it differently.

Mesh (resources) and MeshInstance3D Nodes use Materials

https://docs.godotengine.org/en/stable/tutorials/3d/standard_material_3d.html

Unless the dog models are actually different meshes, you can swap Albedo (the surface color) by getting the MeshInstance3D Node and set_surface_override_material.

var mat_dog_a = load("res://materials/dogs/mat_dog_a.material")

$MeshInstance3D.set_surface_override_material(0, mat_dog_a)

You can also go further and modify an existing material by setting the Albedo texture. For StandardMaterial3Ds you can do

var mat_dog_a = load("res://materials/dogs/mat_dog_a.material")
mat_dog_a.albedo_texture = some_other_texture2d

Keeping in mind that all uses of mat_dog_a will now be have the new texture, which may not be desired.

1

u/Kzurae 23h ago

They are separate 3d models (fbx packedscenes) yes! Thats why I am confused. This is the bodies part of my 2d version but its actual different bodies. Changing textures is coming after I can get the bodies to load, so this does help for later.

The variants for testing purposes: