x

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"

Set variables on Child Actor Component

I have a blueprint class WallReplicator that creates a number of child components (class EyeActor) in its Construction Script.

After I create each child eye, I want to set a variable on it. I tried to do this by casing the result of Child Actor Component to the EyeActor class, but Unreal tells me that this will always fail. Evidently I do not understand what a "child actor component" is.

Add Child Actor Component calls Cast to EyeActor, which shows a warning.

How can I make this work?

Product Version: UE 4.18
Tags:
more ▼

asked Mar 11 '18 at 10:41 PM in Blueprint Scripting

avatar image

Gavin.Kistner
219 8 18 25

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

1 answer: sort voted first

Doing additional research, apparently I need to use the Get Child Actor node (which does not include its name once in use) to get the actor out of the component, and then I can cast the actor to the correct class:

alt text

more ▼

answered Mar 12 '18 at 03:14 AM

avatar image

Gavin.Kistner
219 8 18 25

avatar image TQwan Mar 21 '18 at 09:06 AM

It seems that this solution does not fully work.

In above example the Owning Wall is not available in the Construction Script of the new (child) EyeActor. So if you use Owning Wall in the Construction Script of EyeActor you will get an null warning or error.

For example: You create a new EyeActor (in parents Construct), on EyeActor Construct set default Eye Color to a value based on 'OwningWall'.

Note: Since the Owning Wall is set in the parents Construction Script it will be available on Begin Play of the EyeActor.

avatar image Gavin.Kistner Mar 21 '18 at 01:09 PM

Great to know! If there is a better way to accomplish the same goal without these limitations, please post it as an answer and I'll gladly accept it instead.

avatar image TQwan Mar 22 '18 at 07:52 AM

Hey Gavin,

Basically you were on the right track.

I found a solution which goes around the Construction Script errors in the Child.

  1. Create a new Function in the Child (in your case Eye Actor) and name it something like 'Do Construction'.

  2. Move all functionality from the Construction Script to the new 'Do Construction' Function.

  3. (optional) Add a comment (press 'c') in construction script 'DON'T USE! USE Do Construction Function'

  4. Call 'Do Construction' at the end of your posted solution.

Additional notes:

  • After casting to the Child, in your case EyeActor, I always store this in a variable of the parent (for easy access). Then I make all following calls to use this variable, which makes the code not have so many wires.

  • Before calling the new function 'Do Construction' ensure you first set all required variables. In your case this probably won't happen, however I sometimes don't pass the self reference but set other variables.

  • An additional benefit of the new function is that you can use input parameters, however I don't use this and use Set like you did. This is simply to keep 'Do Construction' consistent with Construction Script.

  • The new 'Do Construction' function is executed After the original Construction Script, so before Begin Play. I use Add Child Actor Component in my Parent's Construction Script which makes everything work inside the Unreal Editor :D (Begin Play is not executed during normal editing, but Construction Script is)

(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