#Parenting different labels to multiple prefabs(or scenes) that I want to stay the same

32 messages · Page 1 of 1 (latest)

hollow anvil
#

How can this be done?
I would like the labels to be attached to the lids of the prefabs

vital glacier
#

You could make the label a child of the lid in the box scene / prefab, give the boxes an export property like:
@export var number: int = 2
and then have each box set their own label's text like:

# Script for box_prefab
func _ready():
  $Lid/Label.text = str(number)
hollow anvil
# vital glacier You could make the label a child of the lid *in the box scene / prefab*, give th...

Wohoo! That is wonderful, gotta try.

However, if I was to make a custom mesh/meshInstance object and wanted to parent that to the lid (or change a lid's child object inside the prefab with another) only for a specific prefab, would that be possible?

For example, would that be possible if I parent 3 different objects to the prefab's lid inside the prefab scene and then hide them - and via script unhide them case per case basis?

hollow anvil
#
extends Node3D

var number = 2

func _ready():
  $/root/boxy/boxy_base/boxy_lid/text_label.text = str(number)
vital glacier
#

Since the script is on the boxy node, node paths in that script (i.e. the path from boxy to text_label) are relative to it, so we don't need the /root/boxy/ part

hollow anvil
#

YES! now it works, yay

#

except....waaaitaminute, ah yes, didn't understand that a node can have only one script assigned to it

#

I even did:

@export var teksti = "A"

So that I can define the string in Inspector and now works very nicely, thank you!

idle stratus
#

@manu regarding your second question which, if I understood it correctly, has to do with having alternative children to objects that are otherwise identical - the proper way is to use dynamic composition rather than "hard-coded" hidden alternatives

idle stratus
hollow anvil
idle stratus
#

@hollow anvil That's why I created it for you. I can upload this example and we can discuss it further if something is unclear

idle stratus
#

Just a moment : )

hollow anvil
idle stratus
hollow anvil
#

also interesting to use prefabs inside of prefabs

idle stratus
#

A good spawning point for bullets, for example

hollow anvil
#

I thought Node3D was the empty

idle stratus
#

Node3D is the base-class for all 3D nodes. I honestly haven't looked into "Marker2D/Marker3D". I just started a few days ago and saw that it is being used as placeholders

#

I guess "prefab" is some Unity term? But as I understand it, everything is scenes/nodes within nodes, so there isn't really anything strange about this either, more than it's more dynamic than you dragging a "player" into a "world scene". Now you can drag whatever you want into it (as long as it works with your interfaces, that is)

hollow anvil
#

another question:

If I have a huge hierarchy, with a couple of child Node3D's even, with a node named as 'superobject' for both objects, is it still possible to reference those by typing $superobject in the root node or a node that's their parent at least?

  1. How to access parent node or a grandgrandparent? is it get_node("./../../../superobjectparent") ?
idle stratus
#

Are you for trying that open-voice channel? I can practice on my finnish as long as no one else is around. : D

hollow anvil
#

okay, why not, but I don't have other questions, I think

idle stratus
#

Sure, but I think it's easier to show a few things regarding refererring up/down along the chain

hollow anvil
#

yes! let's do that

idle stratus
#

Sorry, wife was panicking due to a fault-code in the dishwasher. One moment 😄