Hi! I'm new to Godot, and I'm making my LEGO game multiplayer. I want when a player creates a new brick, the brick will be set to the color the player has chosen. When any player colors the brick, it should sync across all clients. How do I achieve this? Let me know if I need to elaborate!
How to set material of object across all clients in multiplayer
You could RPC a color code and have the script on that object feed it to the material/shader. That would probably be horrible for rendering though. Probably better to have a palette of 8 or so available colors, with a material for each one, and RPC an index. Then load the corresponding material on the brick.
- Edited
award Thanks for the info! Later on, alongside the basic colors, I'll make a color picker for custom colors. Do you think that would be horrible on the performance?
The important thing is to limit the number of materials you need on the objects. Each unique color is a unique material. Objects with the same color can share a material, but different colored objects cannot. It's optimal to have objects share materials so that they can batch together. It's especially important when you have lots of little objects like LEGO bricks. There are some advanced shader tricks you can do to get around this limitation, but none I know give full free reign. So, if you are letting players pick custom colors, you'll need to think about limiting the number of colors they can choose. Maybe players all share a palette, but they each get a part of the palette they can edit the colors. Maybe there's a default palette + 4 custom colors. Something like that. Does that make sense?
- Edited
award Yes! That would work great. I'm starting over on my coloring script, but I don't know how to use arrays. Do you have any advice?
EDIT : Also, should I put the material array in an autoload script or something else?
That's some learning to do. It's a lot of info, and I can't explain it better than the tutorials out there. For learning fundamentals such as arrays, I think GDQuest has some tutorials for learning programming with Godot, and I'm sure there are other tutorials on Youtube focused on the fundamentals with Godot. You should really have a solid foundation before moving on to multiplayer.
Then for multiplayer, I would look in the same places. There are a lot of Godot multiplayer tutorials out there. Look for a recent one so that it's not out of date. I personally haven't done multiplayer in Godot yet, only Unity, but the concepts carry over.
Thanks! I'll do some research : )