I would need to get all Actors from a Folder into an array. They are not spawned into the world, so “Get all Actors” doesn’t work.
So how can I get them all, without having to spawn them all into the world?
Create an array of the appropriate class and populate it. An array of base class will happily reference anything inheriting from it.
If you want to store unrelated classes, an array of Actor type will work here.
Well, the easiest explanation of the endgoal is: I have a bunch of Items. Each is its own Actor (all are also a Child from the first Template). Now I want to have access to the values of each of them for some Interface Stuff.
For example, checking if a certain player is even allowed to see if that item even exists. (That value is for example stored in the item Actor).
Of course I could keep adding every new Item to the “Collection” Blueprint and then spawn them all somewhere in the world (like I do now). But it really feels like a very dirty solution.
Thanks for the answer. But how would I go about populating it (ideally automatically)? Also if I do it as class, the Objects still have to be spawned in the world, so I can access them in the Blueprint.
Atm. I have a Blueprint, where I just add all the Objects and spawn it in the world. If I don’t do so, I can’t access them at all and the Value returns 0.
I believe there’s some misunderstanding here regarding instancing.
I would need to get all Actors from a
Folder into an array.
The blueprints you see in the Content Browser are templates for in-game objects - actors. When you spawn an actor from class (or place it in the level manually), an instance of that class is created. The instances in the level exist and their references can be added to an array.
However, you cannot have valid references to objects that do not yet exist - Spawn Actor From Class.
Also if I do it as class, the Objects
still have to be spawned in the world,
so I can access them in the Blueprint.
How else would would that work? If you want actors in the world you must spawn them first, right? If you want a list of actors to spawn dynamically while in game, you can have their classes (templates) in an array and choose one to spawn.
Atm. I have a Blueprint, where I just
add all the Objects and spawn it in
the world. If I don’t do so, I can’t
access them at all and the Value
returns 0.
Not sure what that means. You either place the object in the level or create them dynamically via Spawn Actor From Class node (there are some other ways - child actors but the basic principle remains the same). The value is 0 because you haven’t spawned them - seem logical, no?
Perhaps tell us what the end goal is - it might be easier to advise. How would that work in the game from the player’s perspective?
Now I want to have access to the
values of each of them for some
Interface Stuff. For example, checking
if a certain player is even allowed to
see if that item even exists.
That makes sense.
Sounds like you want to access class defaults. Essentially - check the details of the class before creating an instance:
Was trying to find a solution for something similar too, Did you found one?