Forum rules - please read before posting.

Bug: Follow Sorting Map not working when loading an NPC prefab at runtime.

edited May 2017 in Engine development
So when I load/drag and drop a prefab NPC while the game is running, the Follow Sorting Map doesn't work/makes no changes to the scale etc. of the character.

The sorting map does work if the game isn't running and I just drop an NPC into the edit window and move it around. Also, it works if the character is saved in the scene, but that's not going to work for what I'm trying to make. I need to be able to load character prefabs into the scene and have them use the sorting map.

Note: I'm not using AC to load the prefabs. It's a different script. But this used to work on previous versions. I could just load a prefab with all the relevant NPC and Follow Sorting Map scripts into a scene and it would automatically follow the sorting map.

Note 2: Yes, I tested a clean install of AC into an empty Unity project and it still doesn't work.

Note 3: Yes, I tried different object arrangements for the Follow Sorting Map script. ie: putting it on the root object and checking off "Also Effect Children" and having the sprite on a child object etc etc.

Any thoughts?

Comments

  • Welcome to the community, @thehmc.

    Please see the front page of the scripting guide: AC handles all updates to its own objects via the StateHandler.  Therefore, the StateHandler's internal record of scene objects must be updated whenever an object is added from a separate script:

    AC.KickStarter.stateHandler.GatherObjects ();
  • Hi, and thanks Chris.

    But is this a change from older versions? In old versions when I would drag or add an object with a FSM component on it, it would just work automatically.

    Is there a way to automate this without scripting? (which I'm not very well versed in)

    Basically I'm using AC with Ork Framework and I need to use Ork to load the prefab, but I need AC to recognize the prefab. Is there maybe an action I can put on the NPC that will tell AC "Hey, I'm in the scene, recognize me." 
  • How old a version are you talking about?  It was like that only a very long time ago.

    If you have access to the script that's performing the addition, you just need to insert the line above into it once the prefab has been run.

    The way to automate it without scripting is to use the Object: Add or remove Action - which is intended for those who want to avoid coding altogether.  One option would be to create an ActionList asset that has this single Action alone, and then run the ActionList manually by running its Interact() function.
  • Perfect. Thanks.

    Honestly it worked until Unity 5.6 and AC 1.56

    Maybe it was because I always had "Edit Mode Preview" checked and it would work whether in the edit window or the game window even if the game was running.

    Now it still works in edit mode, but not when the game is running. I'm guessing it's something different about Unity 5.6.
  • You're welcome.  Indeed 5.6 brought about quite a few subtle changes that have been difficult to uncover.  But I'm not clear on your wording - are things now resolved?
  • Yeah, actually I ended up just putting the script line you specified alone on a new script and attached that script to the NPCs and that works fine.

    Thanks again.
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.