Forum rules - please read before posting.

NPC Start (something like PlayerStart for NPC)

Greetings,

I would like to apply functionality of PlayerStart to NPC, something like NPCStart.
My NPC walks with my player (follows the player) all the time. So when the player enters a room, NPC has to be spawned on particular spot near him, facing a certain direciton.

Basically I need PlayerStart functionlity for NPC.
What I did is, I created "MyNPCStart" script.
MyNPCStart does the job, but the problem occurs when I want to use "Remember transform" with my NPC, or load NPC transform from savegame in any way, what hapens in this case is that MyNPCStart overrides loaded transform.position.

MyNPCStart script sets NPC position and rotation in LateUpdate(), because this is the only point in time where I dont get it overriden by something else setting my NPC position.
So this works but when I save and load, my loaded NPC position gets overriden with position defined in MyNPCStart, beacuse MyNPCStart sets the position in LateUpdate() (after everyone else).

On the other hand, if I set NPC start position and rotation before LateUpdate() (i.e. OnStart()) then this position gets overriden somehow, at the momentI can't see who overrides it and why/how (in this problematic cases it is not overriden by Remember Transform or Remember NPC).

My questions are:
1. Does AC have something like NPCStart component ? I did not find something like that in manual or on the forums.

2. If I have to write my own script, at which point in time (Awake(), Enable(), Update() ...) I should apply position defined in MyNPCStart component, if I want it to be overriden with loaded data from Remember Transform / Remember NPC, but not overriden by anything else

I hope my question is clear enough.
Cheers ! : )

Joakim

Comments

  • Just to elaborate a bit more, if I set my NPC position through "OnStart" ActionList, through actions, this works. But I would like to avoid implementing logic through ActionList for each scene (if previous scene is this then teleport NPC here, else teleport NPC there, else ...).

    Now the trick seems to be that OnStart ActionList does not get executed when loading game,
    thus not overrideing positions loaded through Remember NPC component.
    It looks like loading game does not count as a new scene start.
    So if I could execute my script only in that "scene start" state, which is the state when OnStart gets executed, then it would work I guess. If I could chain my function to "OnStart" ActionList somehow, so only when OnStart executes my script gets executed after that... or something like that...
  • Welcome to the forum, @Joakim.

    First of all, you'll want to use the Remember NPC instead of the Remember Transform component to save NPC data - position and rotation will be included as well.

    NPCs are traditionally manually-moved by using the Object: Teleport Action.  One way to avoid making one such Action for each scene would be to move it to an ActionList Asset, and have your OnStart Cutscene run it with ActionList: Run.  If the NPC and target Marker both had Constant ID numbers that were shared across each scene, then your asset-based Action can look for any instance of these numbers in each scene (see these tutorials).

    If you still wanted to go down the route of custom scripting, bear in mind that characters are best positioned and rotated with their own Teleport and SetRotation functions.  These shouldn't be called every frame in LateUpdate, but if you want them to run at the same time as your OnStart Cutscene, you could consider triggering your script via the Object: Send message Action.

    I will also extend the custom event system for you so that there is an event that can be called whenever a scene begins through normal gameplay (i.e. not from loading) in the next release.
  • Chris thank you very much.
    I went for the Object: Send message Action, and it seems to work.
    All I had to do is add Object: Send message action to my scene OnStart ActionList, set "Message to send" to Custom, slot my NPC prefab as object, and for Metod name enter the name of the method which is located in my script which is attached to my NPC prefab.

    It would be cool if we could listen to this "scene begins through normal gameplay" event, then it would be even easier because we could do everything through script (no need to add action in OnStart for every scene).

    Thank you once again, AC is a great tool !

    Cheers : ).

    Joakim
  • Thank you - lookout for a new event named OnStartScene in v1.55b.
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.