Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get a variable from actor in a list of objects?

Hi, I have an actor with a list of actors as a variable. All the listed actors inherit from the same class with 2 variables (Name, texture). As I understand, I can't use the "actor" type for the list if I want to edit the "default" list, instead I have to use the type "object". But once listed as objects I can't get the actor's info from them.

The use of objects to set elements in a default list is necessary??

Can anyone help me with this process?

  • Make a variable: list of actors. (All actors from different classes but all inherit from the same parent)

  • Set the different elements of the "default" list in the editor.

  • Access a variable from an actor in the list at runtime.

Thank you!

Product Version: UE 4.14
more ▼

asked Dec 29 '16 at 03:38 PM in Blueprint Scripting

avatar image

1 2 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

You can cast to the the actor you want the default variables from. Have a look at this -> https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/

more ▼

answered Dec 29 '16 at 04:44 PM

avatar image

48 3 6 7

avatar image Isrraka Dec 29 '16 at 05:36 PM

Hi!, thanks for the response ! I forgot to mention that in my question! I have tried on the objects in the list the "cast to actor" and "cast to ParentClassName" without success. The cast always fail. Is there any exception involving objects casted to actors?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Get All Actors of Class (the child actor class type) Get (0) and drag off Get Parent Actor.

Cast that into the Class type of the parent.

You should then be able to drag out the variables stored in the Parent class.

alt text

(seems like this is a long way to get there, but no simpler chain comes to mind that would net a valid cast result)

castparenting.jpg (37.1 kB)
more ▼

answered Dec 29 '16 at 04:58 PM

avatar image

766 22 7 36

avatar image Isrraka Dec 29 '16 at 05:43 PM

Thanks! The problem with this approach is that the actors(as objects in the list) aren't instantiated. As I understand the node "Get All actors of Class" searches for actors alive in the world, Isn't it? My list with actors is a library of objects so I can spawn them at demand. Maybe I should reference them in some other way?

avatar image Looniper Dec 30 '16 at 12:34 AM

If you aren't placing them in the map it won't work, true.

If that is the case, you may want to consider using a Game Instance to store the data.

It persists throughout play under all events, and can be referenced from any type of blueprint directly by casting to it with a drawn [Get Game Instance].


Another advantage to using them is that because it never gets "replaced" during play -- you can set a reference to it on BeginPlay in any BPs that will cast to it, and just use that rather than casting each time.

avatar image Isrraka Dec 31 '16 at 11:18 AM

Thanks again! You're right, I should use a Game Instance to do that. But I still got the same problem. Now the game instance has a list of actors. I want to set the default elements of this list. It seems that the only way to do that is using the object type otherwise I have to fill the list at "beginplay". It looks like if I have the actors listed as objects I can't get the data from their variables. The only solution is filling the list at runtime? Is impossible to get the variables data from an actor if is listed as an object and not instantiated?

avatar image Looniper Dec 31 '16 at 11:54 AM

I think I am missing what it is you're trying to do exactly.

If you are using actor blueprints for data storage, without placing them into the map, you are going a very long way to do something simple.

If you are storing lists of dissimilar data types such as the various child classes you have for all actor types set from a single parent - you can just use a Structure to store all of it as a single variable.

Something of an example would help clarify.

avatar image Isrraka Dec 31 '16 at 04:26 PM

I'll try to explain what I'm doing. (excuse my English)

The player has access to a "Lego"-like building system. I have a parent class named "Brick" with a couple of variables (name and icon) and a couple of functions to handle the attachment and detachment between bricks. Then I have some classes that inherit from Brick (like "BodyBrick" or "BuildingBrick") that have some other variables and functions for the specific behaviors of this "bricks". And then I have different actors of type "BodyBrick" for each different BodyPart pieces that I create. Same with "BuildingBrick"

The classes layout is ActualBrick->TypeofBrick->Brick.

In the construction menu the player can select pieces and spawn them in the world. To organize all the pieces and ease the searches the players can select which type of pieces are shown to them (BodyPart, BuildingPart).

I want to be able to have a list with all the bricks in the game(or a different list for each type of brick). I need to be able to set the default elements of this list in the editor and at runtime I want to get the name and icon variables of the parent class "Brick" to fill the different buttons of the selection menu with the appropiate names and textures. From this list I also want to get the actor to spawn when the player makes the selection in the menu.

I will try what you said and use a structure of "Bricks" instead of a list in the Game Instance. Do you think this is the proper way to handle this system? Thanks again!

avatar image Looniper Dec 31 '16 at 11:36 PM

I think I understand better what you are trying to do.

A structure is just an array that can store different Types of data. A blueprint, a float, a text variable...

That is why I suggested it - since you are asking about references to Actors/Pawns and various variables associated to them.

avatar image krazgore Jan 10 '17 at 05:29 PM

You can make an array of classes. In the child blueprint you can set the default variables of the parent. If you don't see these in the child make sure Show inherited variables is checked ->like this.

untitled.png (148.5 kB)
untitled2.png (17.2 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

At the end I used a list of classes in MyGameInstance and a function to return the appropiate class. The function inputs an integer and outputs a class type. The menu bluprint then can "spawn actor of class".

The problem now, unrelated or not, is that the project crash when loading and I can't continue. The crash points to the Menu blueprint so, perhaps it is related. I'm on 4.14.3.

Thanks for the help!

Edit: Here is my crash and a workaround to resolve it: https://answers.unrealengine.com/questions/528455/child-actor-component-keeps-corrupting-its-parent.html

more ▼

answered Jan 12 '17 at 10:03 AM

avatar image

1 2 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question