can you spawn actors in the constructor script of an actor blueprint

hi

can you spawn actors and attach them to a component in the constructor script of an actor blueprint
when i try this in the actor blueprint constructor script spawning the actor fails and attaching it also fails
but when i do it after beginplay it seems to succeed

thanks

Don’t think so, but once they’re added you can organize them however you like :blush:

Here’s an example:

Meant to reply to your OTHER recent topic :rofl: :rofl: Switched them up :sob: :sob: Link below :innocent:

1 Like

switched to actor component instead

that seems to solve the problem

Hey @barbrian0723! I just took a look at this topic of yours as well, you shouldn’t be able to use the Spawn Actor node inside the construction script. In your update above did you mean you found a workaround for your objective? If so, that’s amazing to hear :star_struck:

I haven’t even tried that myself so wanned to see what happens, but I can’t even place the node in the construction script! By failing did you mean that or were you able to actually place the node? I wonder which version you’re on.

There should be no problem with attaching though. If you encounter any issues on that, you can share your blueprint code for us to take a look :innocent:

1 Like

lol

initially i tried to spawn actors inside an actor blueprint as an easier why to construct a bigger actor

i tried this in the constructor script to be able to view as i construct

i used the spawn actor node and attach actor to component nodes with attaching the spawned actor to a scene component from / of the base actor blueprint

but the spawn actor node fails and return none. obviously the attach node will then also not work

i subsequently moved everything out to a function called by the begin play event

then spawn actor worked and also the attach actor to component node

i then switched to the add child actor node to spawn the actor instead, and then/ now i can spawn actors inside the constructor script as child actors

1 Like

Child actor components have some caveats that annoyed me so far

  • can’t select them in editor
  • they still count as own actors (so they appear e.g. in GetAllActorsOfClass)

in case anyone finds a way to actually spawn and attach actors in construction script let me know please

The big question is what problem do you have with doing it in the begin play? It’s the same thing.

  • Why spawn actors on BeginPlay when you can pre-generate your map? Makes generation less debuggable and also adds another loading step after a map is started
  • Another use case is generating a level in the editor and then manually tweaking it. Doesn’t have to be in prod, there’s still a lot of benefit being able to do that during dev time

I know you can spawn actors in the editor in other ways. That’s also not straight-forward since the engine requires you to set some random ownership-related fields that you need to dig up from old forum threads

So, not the same thing - at all