Forum rules - please read before posting.

Parent instantiated object at runtime?

edited April 2021 in Technical Q&A

I'm making a small puzzle with blocks, where I spawn the Main block object and spawn Small block objects to an empty scene. I want to parent Small ones to the Main block. Once blocks are placed on the grid I want to repeat it( spawn and parent again).
But I can't since it tries to parent to the prefab and not addressing the spawned objects in the game.
Using actionlist Object: Set parent Both fields Object to Affect and Object to Parent to are set to prefabs.
I understand that's the cause of it.
So how to do it the right way e.g. tell AC to find new Main block and new Small blocks and parent Small ones to he main one.
Using latest AC and Unity versions.

P.S. At the moment I handle everything through script and only use AC to instantiate/spawn objects.

Comments

  • What AC version are you using?

    If such an Action is used by an ActionList asset, or if the objects it references cannot be found in the scene (i.e. are prefabs), it should record the Constant ID values of those objects - and use them to locate their scene instances at runtime.

    Make sure your prefabs have Constant ID components with Retain in prefab? checked, and re-assign them in the Action if they didn't.

    This technique won't work, however, if you're spawning multiple instances of the same prefab.

    If you're doing everything in script except for the spawning/parenting, it may be best to incorporate that into the script as well. That way you're guaranteed to have a reference to the spawned instance, separate from the original prefab.

  • edited April 2021

    Roger that. Did it with the script. Thank you for your time Chris as usual. Keep AC alive for many many years :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.