It is exactly opposite situation of duplicated node. It is a single data block used to instantiate and shape 3 different nodes. I believe it is executed this way :
- There is a dictionary or a node for every weapon, like “machine_gun”, containing info about its properties, like “mesh” “maxammo” “upgrade” “range” “cost” “is_in_inventory” and so on.
- It is set to send a signal whenever any property is changed within it. Signal contains information about node name and all its properties after change
- Three different nodes are connected to this signal : graphical representation of a weapon, UI representing statistics of a weapon, viewport conatiner showing current mesh of a weapon. They are reacting to specific properties change in signals.
So there are potentially infinite amount of data blocks for weapons, that are invisible in game.
There are three nodes entirely independent from each other, but they are dependent on a signal sent by these data-blocks representing weapons.
There are no duplicates, only a class ( weapon ), that all weapons inherit from
The problem is that it’s not just a mesh, but a scene with different nodes (e.g., SpotLight). So, I need to send signals to duplicate this scene in all places where it will be displayed?
thisischico | 2022-08-15 19:41
No, don’t duplicate any scene.
Look, You will have some weapons nodes stored in array, not childed to anything.
This is an example of how it can work :
Your menu mode has reference to array of weapon nodes, and when player chooses weapon name, subsequent weapon node becomes “current” and it sends a signal.
Wievport container node consists only of camera, light, background and empty mesh instance. It catches the signal about weapon, and mesh changes accoriding to information about this weapon.
MeshInstance.mesh = info.mesh
The player is very complicated set of nodes, but it also receives this signal, so he can adapt in-game statistics like reload time, shot damage, ammo type, zoom-in possibility, some special effects and everything, that depends on weapon type. Player also has an empty mesh, attached to the hands bone, that only changes mesh to a current weapon, nothing else.
Finally, UI element receive this signal, so all its submenus and labels can display statistics of a current weapon.
Whenever a statistic changes, for example You apply upgrade to a weapon, signal is resent, and all these nodes make changes too.
One signal comes from one node, but all amount of nodes can receive it, so nothing needs to be duplicated.
I understand what you’re talking about, but the weapon should be a scene, not a mesh. Unfortunately, the mesh has no light sources and cannot simulate a double render, and without this, the weapon will not be able to have a laser, flashlight and scope.
Upd: That is, I would not want to do hacks with a flat image of scope, light and laser from the center of the screen and etc
thisischico | 2022-08-15 21:03
no no. You need to think more programmatically.
Lets say You want to have 10 weapons in total. You don’t want to create 10 scenes for FPP, 10 more scenes for profiled view in menu, and 10 more scenes for menu displaying statistics.
You want to have 10 data bases, and one scene for FPP visualisation, one scene for profiled view, and just one scene for stats display.
What I am saying is, your player will have a specific visual weapon scene in FPP, and this scene will NOT need every information every weapon has, but just minimum, like a mesh and if its one-handed, if it has laser sight and so on. So when You change your weapon from pistol to shotgun, You don’t have to preload and instantiate huge shotgun scene and queue free huge pistol scene, instead only a mesh and some visual gimmicks change.
The same goes for other nodes - they use shared information from signal and only change absolutely nesesarry things.
In the game, which I cited in the example weapon behaves everywhere fully (probably except as an item), in the view window, in the weapon assembly mode and in the 3d hands. To get the same functionality, would I have to somehow add a double scope renderer separately, as well as light and laser nodes for each such situation? And then I’d still have to instantiate the nodes for that anyway. Also I could use to render one player in different places (which would definitely be the scene), a car and other things, and it could also play animations, is there a more versatile way?
thisischico | 2022-08-16 17:25
Just in case: flashlight, scope, and laser must be nodes since there can be several of them on one weapon.
thisischico | 2022-08-16 17:41
It is all just a mesh. You can use single weapon 3d asset for all of these things. I would model weapon with all scopes and flashlights and upgrades as separate objects in one 3d file, and name them accordingly while remembering to keep one naming convention for all the weapons I model. This way You can just hide/unhide things when signal provides information about scopes and flashlights.
Perhaps You wish for one scene using asset automatically change when another scene with this asset changes, but this automatization must be done manually. I would just make 3d scene with asset only, to listen to signals mentioned above and make changes to the asset accordingly. You could then use one instance of such scene for hands3d and another one as a child of viewport container with camera for profile display.