Forum rules - please read before posting.

Instantiated prefabs have the same ConstantID

mekmek
edited August 2018 in Technical Q&A
Spent about a week trying to debug this.
AC version:  1.64.2
Unity: 2017.4.1

I have a Door prefab:


DoorParent is empty.

Doors1 has:


Constant ID is set to Automatic and Retain in Prefab is unchecked.

This Door prefab is instantiated at runtime throughout the world (I am using DunGen to generate the level.  Every wall has a doorway created procedurally.)

When I Run and check each Door in the scene, every one of them has the ID 11190210.

What am I missing?

I have a DoorHotspot child that uses an ActionListAsset to open the Door parent.  It tries to reference the ConstantID but this doesn't work because all the other doors in the scene use the same Constant ID.  I was hoping there was a "Hotspot Parent" action to reference the Door that I clicked the hotspot child on, but it doesn't seem so.

I have to keep the DoorHotspot as a child of the Door object itself because the Door object needs to be on the Door layer (since I don't want pathfinding to think of it as a obstacles).  Since Hotspots can only be set up on one layer, I want to leave them on Default and not change them to Door.  If I didn't need to make the hotspot as a child, or I could reference a hotspot's parent, this would be easier.

Comments

  • Is retainInPrefab marked on the ConstantID component on your prefab? I believe if that is checked then all instances will share the same ID.
  • No - Retain in Prefab is unchecked (confirmed in the screenshot above)
  • It looks like the screenshot is cropped below - what else is under the Constant ID?

    I have recently uncovered a bug in which CID numbers from prefabs were not being re-assigned correctly if a GameObject had more than one ConstantID / Remember component on it.  A fix for this will be included in the upcoming update.

    Is this the same situation?
  • mekmek
    edited August 2018
    Hi Chris - here is the full Inspector:

    Prefab structure:


    DoorParent:



    Door_Frame:


    Doors1:



    DoorTrigger:


    DoorHotspot:



    I only have 1 Constant ID on the prefab, on "Doors1" child.
    After running my level generation, every Doors1 object ConstantID is the same - 1879184

    I have tried setting back and forth from manual to automatic to attempt to reset it, checking and unchecking retain in prefab, as well as remake the constant ID component.  Always has the same result.
  • What do you mean by "running your level generation"?

    I can't recreate the issue myself, but I'm doing it by duplicating a prefab instance manually in the Hierarchy - if you're running some script to lay these down for you, it may be that you also have to also check for duplicates through script too:


    Do IDs correct themselves if you lay down instances of the prefab manually?
  • Correct - they do work as expected if I lay down the prefabs manually.

    For level generation, I use DunGen:
    https://assetstore.unity.com/packages/tools/utilities/dungen-15682

    This places prefabs at runtime.  I would have thought the ID assignment would still work as expected regardless?
  • I have solved this by invoking the method you pasted right after level generation is finished.

    Now the problem is involving AC knowing which door to affect.  Since the Hotspot is a child object of the Door, how will clicking on that Hotspot know that it needs to affect its parent?

    Doors1 is a parent to DoorHotspot
    Doors1 cannot have the Hotspot component directly on it because it needs to be on a separate layer for navigation purposes and there is no option to allow Hotspots to be on multiple layers

    Hotspot settings:
    image

    AssetFile Interaction "Door_Open":
    image

    If I make the Parameter = Hotspot, it will only affect the gameobject the hotspot is attached to, not its parent.

    If I make the Parameter = Hotspot, it will also require a ConstantID, meaning I have to remove the Remember Transform ID from the Door parent because of the bug.

    If I make the Parameter = Door's ConstantID, it only knows one specific door.

    I need to be able to grab the ID of the Hotspot's parent that has just been interacted with.


  • The bug only applies to multiple ID components on the same GameObject - having an ID value on the Hotspot wouldn't affect the parent.

    I shall look into incorporating a custom event that triggers when an ActionList is run - that way, it'll be possible to write a simple custom script that amends the ActionList's GameObject parameter to be the parent of whatever it's first set to.

    Also - though I can't say if it'll be possible just yet - I'll look into the possibility of allowing Hotspots to be on multiple layers.
  • mekmek
    edited September 2018
    So as of right now, is the only way to affect a specific prefab instance that it must have a Hotspot component directly on it?  If that's the case, then I believe the multiple ID component bug would also affect it - you'd need both a Constant ID and a Remember component (in the case of opening a door) right?  
  • I've gone ahead and just re-done doors using Playmaker so its outside of AC.
  • edited September 2018
    All Remember components are subclasses of ConstantID - and include a Constant ID value in their Inspectors.  Having a Remember component on a GameObject gives it a Constant ID value automatically.

    Unfortunately, Hotspots must be left on a single layer.  However, the next AC release will allow you to modify an ActionList's parameters through a new "OnActionListRun" event, so that you can dynamically change a GO parameter value to its own parent with a simple script.
  • Thanks for that!

    It would be great in the future if integrating that function into AC Hotspot would be included.  I normally parent my Hotspots to other objects and it would be nice to just check a box than adding a script each time.  Just a thought.

    Cheers -

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.