Use Add Child Actor Component with a variable for the Class

I’m using a Add Child Actor Component and it placing the actor exactly where I want it. However I want to be able to set the class using any given item out of an array. Is there a way I can do that?

I have tried using SpawnActor instead, then using Attach Actor to Component, but using that method I never saw the actor.

1 Like

Hi,

Both of these solutions seem to work for me:

1 Like

You can’t make an array of classes if that’s what you’re asking. You can create a user-defined structure though.

Hmm, currently I’m using a array of actors. When I get an item out of that array I can plug it into the Class pin on Spawn Actor. It would be awesome if Add Child Actor Component had a Class pin.

Thanks for the screenshots! At least I know I’m trying close to the right thing. Unfortunately I still can’t see the actor when using Spawn actor. I’ve tried lots of options for different transforms and also the different options in “Attach Location Type”.

Also, it looks like you’re blueprints are in the Level Blueprint. I’m trying to do this inside my own blueprint. I don’t know if that would make much difference. Where you use “Default Scene Root” I just use “Get Root Component” or drag in the “Scene” object.

This is not the Level Blueprint, but an Actor-Blueprint. Default Scene Root is the default component inside an actor, as long as you dont add anything to it.

When you use the spawn actor method, are you sure that you have set the default value of the class variable? Its not enough that the variable is of the right type… Thats a mistake I made creating this Blueprint, and it would end in the same result as yours.

That wasn’t my problem… I was trying to use SpawnActor in a function called by the construction script, which apparently fails without any errors or warnings. I moved it elsewhere and everything works now. Thanks for your help!

You can set class of ChildActorComponent by this way

2 Likes

works! thank you

made a short tutor in russian about this topic.