Is there anyway to easily interact with all devices of a certain type?

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 can use Gameplay Tags to do this!

3 Likes

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)
2 Likes

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.

2 Likes

@SeedohFN @im_a_lama You both are awesome, thank you so much! Both responses were very insightful to me figuring out what I’m trying to do.

2 Likes

Ahhhh I see now why tags fit the most in that scenario. Never used tags anyways

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.