Forum rules - please read before posting.

[Bug] Prefabs passed as parameters to ActionLists not correctly handled, under some circumstances

Unity 2018.1.6f1, AC 1.63.2

To replicate the problem:

1) Clean (2D) Project, using AC defaults

2) Use AC CharacterWizard to create a new NPC called NPCTest, with Constant ID set as "Retain in Prefab"

3) New Scene with a Path for NPCTest to follow

4) The Scene's OnStart ActionList should contain the following Actions:
    > Object AddOrRemove/Add NPCTest relative to the Scene Path
    > Character MoveAlongPath NPCTest MoveOnNewPath of the Scene Path

5) New AssetBased ActionList "InteractNPC_Parameterised", with parameter "NPC_Prefab" of type GameObject, with a single Action:
    > Character MoveAlongPath StopMoving CharacterToMove: parameter "NPC_Prefab"

6) New AssetBased ActionList "InteractNPC", with a single Action:
    > Run ActionList "InteractNPC_Parameterised", passing the NPCTest Prefab GameObject in the "NPC_Prefab" parameter

7) Amend NPCTest Hotspot UseInteractions: Use, Interaction = "Interact_NPC"

8) Run the Scene

9) Clicking on the NPCTest character will produce a NullReferenceException


Note that changing the ActionList in 5) to any other kind of Character or Object based action (such as FaceObject etc) will also produce the same NullReferenceException

Also note that during testing I discovered that parameterised Prefabs ARE handled correctly under most circumstances (which initially made me think I was mistaken in ever thinking that they weren't). However, it just so happens that my particular use case involves something very similar to the setup defined above, where the parameterised ActionList is invoked by interacting with the Hotspot on the NPC character, and it's that bit that seems to be the fly in the ointment

Comments

  • Thanks for the clear steps - I'll follow them and see how I go.
  • This is technically correct - you're passing the original prefab as a parameter, for Actions to use how they see fit.  The NullReferenceException error appears because it's actually the prefab that it's attempting to stop moving.

    The current way around this is to place an instance of the prefab in the scene, drag that into the Action field (so that it knows you want to affect an instance, not the original prefab), and then remove the prefab from the scene.

    I do concede that it's not the smoothest workflow, however.  In this scenario, I'll look into adding a per-parameter option to let you state whether the prefab, or a scene-based instance of it, is what should be passed.
  • Thanks for looking into the issue Chris

    Having the ability to add a per-parameter option stating whether you're using a prefab or a scene-based  GameObject definitely sounds like it would be a useful feature to have in AC

    However I should say that since posting this I've revisited how my Player/NPC actions are handled, and I've decided to completely rewrite them to use a somewhat different strategy from the one outlined above, which means that my own requirement for such a facility has faded somewhat

    What I'm planning to do now is to make use of the fact that you can pass the Hotspot itself as a parameter to Interactions. So, the first thing I'll do when processing an interaction is to run a series of checks against the passed Hotspot, and determine which NPC is being acted on. I'll then store that information in a PopUp field, which I'll subsequently use to drive all further ActionLists related to the particular interaction

    This actually seems like it will be a far better approach than the one I was originally using, and basically means I'll no longer need to pass GameObjects around as parameters - if there are any Prefab-specific actions to perform then they will take place within an ActionList (driven by the PopUp field) and I've never experienced any problems with that style of Prefab processing

    It should actually simplify things quite considerably too. So, whereas in the past I had to set up one Interaction per Item per NPC (e.g. UseThingeeOn_NPC1, UseThingeeOn_NPC2... etc), I'll now only need to have a single Interaction per Item - UseThingee, with a parameter of Actor_HS
  • +1 on having an option to state whether the scene based instance of it should be passed, as I've had a similar problem
  • It'll be included in v1.64.0.
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.