Difference between revisions of "Cell Attachment Analysis"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Rasikko
(Created page with "This more of a self reminder for myself but I hope it proves useful to others. It's been proven that cell attachment/detachment is the result of the engine checking a bool on...")
 
imported>Rasikko
Line 3: Line 3:
It's been proven that cell attachment/detachment is the result of the engine checking a bool on the objectreference as to whether or not its cell is/was attached/detached. See [[OnCellAttach - ObjectReference]] talk page.
It's been proven that cell attachment/detachment is the result of the engine checking a bool on the objectreference as to whether or not its cell is/was attached/detached. See [[OnCellAttach - ObjectReference]] talk page.


However, I'm going to extend the basic info about these two things a bit.
However, I'm going to extend the basic info about these two things a bit by breaking it down into 6 scenarios.


It's all about the objectreferences in the cell ''with'' the player/reference that has scripts attached them containing these events.
Scenario 1<br>
Player is in the reference's parent Cell:  '''[OnCellAttach]'''<br>
Player leaves the reference's parent Cell: '''[OnCellDetach]'''<br>
<br>
Scenario 2
Player is in the reference's parent cell'''[OnCellAttach]'''<br>
Reference moves to another cell:   '''[OnDetachedFromCell]'''<br>
-Because the reference has moved from its previously attached cell, to a cell that is currently not attached.<br><br>


My research is mainly for interiors, so here goes.
Scenario 3<br>
Player is in the reference's parent cell:  '''[OnCellAttach]'''<br>
Player leaves the reference's parent cell: '''[OnCellDetach]'''<br>
Reference moves to another cell:          '''[OnAttachedToCell]'''<br>
-Because the reference and the player both moved to the same cell and in the case of the reference, this new cell became attached.<br><br>


These are for more reliable then any other load event associated with Cells. They can be used for a large range of tracking, provided that you understand how they work.
Scenario 4<br>
Player leaves the reference's newly attached parent cell: '''[OnCellDetach]'''<br><br>


OnCellAttach will always fire for an objectreference when another reference(like the player) enters its parent cell. This is expected behavior. OnCellDetach will also always fire for an objectreference when another reference(again like the player) leaves its parent cell. Notice that these events weren't firing as the result of the objectreference itself changing cells.
Scenario 5<br>
Player is in the reference's parent cell from scenario 3: --<br>
Reference moves back to the previous cell: '''[OnDetachedFromCell]'''<br>
-Because the reference has moved from currently attached parent cell to the previous cell which was detached.<br><br>


In short, the steps are:
Scenario 6<br>
* OnCellAttach
Player is in the cell that the reference just left from scenario 5: --<br>
* OnCellDetach
Player moves back to the previous cell where the reference is: '''[OnCellAttach]'''<br>
Player leaves the reference's parent cell: '''[OnCellDetach]'''<br>


To reduce confusion, I'll refer to the object with the parent cell as the objectreference and the object in it's parent cell as the player.
Now let's talk about the objectreference changing cells. There is where [[OnAttachedToCell - ObjectReference]] and [[OnDetachedFromCell - ObjectReference]] come in.
The above still applies but with some new additions. If the objectreference '''moves to another cell''', OnCellDetach will fire but '''for the player that left the objectreference's parent cell BEFORE the objectreference was moved'''. Yes, OnCellDetach will never fire as the result of the objectreference changing cells. The objectreference hasn't moved yet. When the objectreference completes is movement to the next cell, OnAttachedToCell will fire. As its name implies, the new cell is attached to the objectreference thereby becoming its new parent cell and OnCellDetach can fire as normal if the player leaves this cell. Now, if the objectreference moves back to the previous cell, '''but the player stays put''', OnDetachedFromCell is fired and this is because, as its name implies, it's '''moving from an attached cell to a detached one'''. To clarify, the objectreference's new parent cell '''is a detached one''', while the player is in an attached one. OnCellAttach can fire again as normal if the player re-enters the previous cell.
In short, the steps are:
*OnCellAttach
*OnCellDetach
*OnAttachedToCell
*=>OnCellDetach
*OnDetachedFromCell
*=>OnCellAttach
--[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2021-10-15T15:30:21 (EDT)
--[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2021-10-15T15:30:21 (EDT)

Revision as of 11:19, 17 October 2021

This more of a self reminder for myself but I hope it proves useful to others.

It's been proven that cell attachment/detachment is the result of the engine checking a bool on the objectreference as to whether or not its cell is/was attached/detached. See OnCellAttach - ObjectReference talk page.

However, I'm going to extend the basic info about these two things a bit by breaking it down into 6 scenarios.

Scenario 1
Player is in the reference's parent Cell: [OnCellAttach]
Player leaves the reference's parent Cell: [OnCellDetach]

Scenario 2 Player is in the reference's parent cell: [OnCellAttach]
Reference moves to another cell: [OnDetachedFromCell]
-Because the reference has moved from its previously attached cell, to a cell that is currently not attached.

Scenario 3
Player is in the reference's parent cell: [OnCellAttach]
Player leaves the reference's parent cell: [OnCellDetach]
Reference moves to another cell: [OnAttachedToCell]
-Because the reference and the player both moved to the same cell and in the case of the reference, this new cell became attached.

Scenario 4
Player leaves the reference's newly attached parent cell: [OnCellDetach]

Scenario 5
Player is in the reference's parent cell from scenario 3: --
Reference moves back to the previous cell: [OnDetachedFromCell]
-Because the reference has moved from currently attached parent cell to the previous cell which was detached.

Scenario 6
Player is in the cell that the reference just left from scenario 5: --
Player moves back to the previous cell where the reference is: [OnCellAttach]
Player leaves the reference's parent cell: [OnCellDetach]

--Rasikko (talk) 2021-10-15T15:30:21 (EDT)