Hello! I currently have a small script that makes it so anytime a specific log from a physics_tree_device is destroyed the player will get 100 Gold. Is there a way to make this apply to EVERY physics_tree_device in the level without having to make an array and pick every single one manually in UEFN? The code I currently have is as follows
log_break_granter := class(creative_device):
@editable
GoldGranter : item_granter_device = item_granter_device{}
@editable
Trees : physics_tree_device = physics_tree_device{}
GrantGold(): void =
AllPlayers := GetPlayspace().GetPlayers()
for (Agent : AllPlayers, Player := player[Agent]):
GoldGranter.GrantItem(Player)
OnBegin<override>()<suspends>:void=
Trees.LogDestroyedEvent.Subscribe(GrantGold)
You might need to make it an array, here is how you can assign the event to each tree in the array without doing it manually:
@editable
GoldGranter : item_granter_device = item_granter_device{}
@editable
Trees : []physics_tree_device = array{} # Make it an array
GrantGold(): void =
AllPlayers := GetPlayspace().GetPlayers()
for (Agent : AllPlayers, Player := player[Agent]):
GoldGranter.GrantItem(Player)
OnBegin<override>()<suspends>:void=
# This will go through each tree in the array and assign the event
# So you don't have to do it manually
for (Tree: Trees):
Tree.LogDestroyedEvent.Subscribe(GrantGold)
No matter what you have to identify each item in your scene. Fenzy’s way is the most ideal in your situation as you can tag one of them, then just duplicate that object and the tag will be there.
If you use an array in an editable, you have to do as you mentioned… Select every one of them.