How can I get a actor by variable?

I’m having trouble of getting an actor in my level by using global variable. For example:

I have Ball Blueprint, And each of this Balls have their own ID, 0 ,1, 2, 3 etc. When my Character enter to a trigger box, This trigger box, I want to get the Balls with ID 1, 2 or only 1. Is it possible?

In more likely language programming, is more like this: Object obj = Object.get(1)

Hi there,
I am not sure how flexible you need to be:

1: In my example I assumed that you manually place the Balls into your Level and therefore you got the Reference in the Level Blueprint. But you can also generate them in within the LevelBlueprint and add them into the array that way.

2: Who decides which Balls are returned?

  • If you put the Balls and the TriggerBoxes into your Level manually, and each Box gives you the predefined Balls, then you actually just need to assign the Balls to the TriggerBoxes. (TriggerBox with editable Array that you can fill within the WorldOutliner)
  • If you need to decide within the GameMode which Balls should be selected then you need to pass the Balls to the GameMode to handle that. This is what my sample does:

Balls and Triggers (Parent class TriggerBox) in the Level:

99830-worldoutliner.jpg

GameMode has the Array of Balls and the Event that gets called by the Character when entering the Trigger:

The LevelBP that fills the Array (you can spawn the Balls and assign them at runtime as well):

And the Character BP that calls the Trigger Event

So now you got everything you need within your GameMode.
You can take the information you need from the TriggerBox.
BallArray->Get gives you the Ball by Index which should be the ID if you put them in in the correct order.

If your usecase allows you to assign the Balls to the TriggerBox, then you do not need that Array (incl LevelBP) at all. Then you just need to take the Balls from the TriggerBox parameter of the TriggerBoxEntered event and move on with all the fancy things that will follow :slight_smile:

hope that helps :slight_smile: Marooney

Thanks for the explanation! It might works what I’m trying to do! I will be testing this week and if it works, I will accept this answer as correctly. Thanks again.

And if it does not work, just ask :slight_smile: It’s an architectural thing so there are many ways to go. The shortest path depends on how precise you can explain your goal :slight_smile: