#Need help figuring out why a list is changing between scenes

1 messages · Page 1 of 1 (latest)

jade echo
#

I have class that is shared between scenes through an intermediate object and it seems to be changing in between the Start and Awake callback functions of the object, and i'm not quite sure why.

In the screenshots, notice how in the pic where Awake is highlighted, in the watch window, MuseSensors has 6 items. In the pic where Start is highlighted, it only has 5.

@latent sable

The context is that I have a scene that has an object called Settings and Data (see screenshot)

That object uses this script SceneSettings, which references a static instance of the DataCompanionListener class.

In between the Awake and Start callbacks of SceneSettings, a list in the static instance of DataCompanionListener seems to change, and I don't know why. Any help figuring out why, and how I can stop that from happening, woudl be appreciated.

latent sable
#

There is no "static instance"

jade echo
#

sorry i misspoke

latent sable
#

there's a static reference variable that is pointing to instances that are very much in scenes

jade echo
#

yes it's a static variable, it's not being instantiated

#

but my point is

#

(and idk why this is the case), but the way it was written

#

scenesettings declares a datacompanionlistener variable

latent sable
#

You were saying this before:

datacomponentlistener is in that scene "directly" declared in the hierarchy. but in a different scene, it's declared a bit differently (illshow the unity editor screnshot one sec)
Can you show what you mean?

jade echo
jade echo
latent sable
#

yeah...

jade echo
latent sable
#

Well I don't see it "accessed" at all - but yeah it's odd. I would expect that if you have a static instance variable or property, it's essentially a singleton and everything should access it through that variable/property

#

I don't see any relation to the original question here though

jade echo
#

my core issue here is that there's a member in datacompanionlistener called musesensors

#

and it's modified between the awake and start callback functions of scenesettings

#

there's an item in there that gets removed from the end

#

and i can't figure out why

#

or how to prevent that

latent sable
#

Well for one are there any scene transitions going on?

#

if not, the only way that could be happening is if some code is doing it.

#

so just search the code for references to that list and see what's changing it

jade echo
#

it happens in the midst of a transition into the scene

latent sable
#

So we have to be careful here

#

let's make sure we're actually talking about the same instance of the script

#

It would be good to check the InstanceID of the DataCompanionListener in the debugger

jade echo
#

which script? scenesettings or datacompanionlistener?

latent sable
#

DataCompanionListener

jade echo
#

oh kk

latent sable
#

the one that owns the list

jade echo
#

one second

#

ok so

#

how do i find the instance id in the watch window?

#

it doesn't seem to be a property on the datacompanionlistener

latent sable
jade echo
#

i cannot find one

#

right i guess because the instance is null

latent sable
#

it looks to me like it's not ACTUALLY null

#

it's Unity's fake null

#

Which could/would partially explain the issue

jade echo
#

oh i did a thing accidentally btw

latent sable
#

This is what you see when an object was Destroy()ed

jade echo
#

i accidentally set one of those fields to the object id

#

oen sec

#

i right clicked and selected set as object id and idk why

#

one sec

latent sable
#

I think this is maybe a "Rider is doing something cool" thing

#

m_InstanceID is maybe an unmanaged C++ field

jade echo
#

ok so i fixed the oject id thing

#

can you explain how you mean by fake null?

latent sable
# jade echo

btw when you're in this view you can do DataCompanionListener.Instance.GetInstanceID() in the immediate mode command window thing in the debugger

latent sable
jade echo
latent sable
#

even though the ferences are not actually null

latent sable
# jade echo

ok cool so now can you see if this instance ID is the same for the two debugger contexts

#

so we can see if we're even looking at the some object

jade echo
#

ohh kk

latent sable
#

right so we're maybe dealing with two completely different instances of the component here

jade echo
#

so like after SceneSettings.Awake, it invokes DataCompanionListener.Awake

#

and it looks like after Instance = this, in datacompanionlistener awake

#

the object is changing

latent sable
#

yeah that's expected

#

you're changing scenes

#

the copy of the object in the old scene will have been destroyed

#

now there's a new one in the new scene

#

I would start by looking at the two scenes in question and see if there is a DCL in each scene

#

(at edit time)

jade echo
#

i see ok. let me check soething

latent sable
#

And by the way if you're accessing DCL.Instance from the Awake function in SceneSettings, that can potentially be problematic for this exact reason

#

A good rule of thumb is to do "self init" in Awake, and then initialization that depends on other scripts being initialized in Start

jade echo
latent sable
jade echo
#

Also why is the list being changed in the second scene? I dont have any logic to remove from the list in question

#

I have some logic to add to it

tranquil juniper
#

Still not solved?

jade echo
#

A bit closer to the cause

#

But not quite there yet

latent sable
#

There are two lists

#

they have different contents

jade echo
#

Right but like i don't have any initialization logic for the lists

tranquil juniper
#

why isnt this stuff you need in many scenes in a scriptable object instead?

jade echo
#

I inherited the codebase

latent sable
jade echo
latent sable
#

So again - I would just be looking for them in the two scenes and seeing how they are set up in the inspector

tranquil juniper
#

^ search the hierachy using t:MyType

latent sable
#

If the intent is that the list is the same everywhere - you could/should be using a prefab for the object that has this script on it

jade echo
latent sable
#

so that you can change it in one place without it getting out of sync

jade echo
#

The wonky thing is that the dcl instance isnt exposed directly in the second scene

latent sable
#

Alternatively - just set it up once in a "bootstrap" scene and make it DDOL

latent sable
#

so you need to figure out where

jade echo
jade echo
latent sable
#

First I would take a closer look at the scene with the hierarchy search function

#

second I would put Debug.Log in Awake on DCL and see where it's getting instantiated from, if it is

tranquil juniper
#

or are you presuming

jade echo
latent sable
#

It might help if you shared some of this code with us

#

Especially DataCompanionListener

jade echo
#

Its all closed source otherwise I'd link you the repo lol

latent sable
#

It looks to me like DCL is just a pretty standard singleton

#

It's just assigning itself as Instance when it's created

#

so the thing to do is figure out where it's being created. 95% of the time, it's just placed in the scene from the editor at edit time

#

if not, then it has to be getting instantiated from somewhere - hence the Awake Debug.Log suggestion from earlier

#

or using the debugger

latent sable
# jade echo ohh kk

Like - in the debugger right here, you can look at the stack and see what is Instantiating the object

tranquil juniper
#

or debug log with a context arg

latent sable
#

Lots of tools at your disposal here - so let us know when you track it down

jade echo
#

Ok!!!

#

Thank you

jade echo
#

The callstack window seems to be empty and the threading window doesn't shine any more light on the invoker of dcl hmm

tranquil juniper
#

Because Awake is called by native engine code

#

thats why we told you how to figure out where this component is...

jade echo
#

Ok so i've made some progress

#

I now have a more concerete question

#

Ok so like I have bunch of scenes that operate the same way

#

that take settings data from another object

#

dcl is part of that

#

i have this one object Muse Listener

#

That reused in like 20 different scenes

#

I need to add back in the 6th element hree in the inspector

#

but like can i do it once instead of ahving to modify every single instance where this is used?

tranquil juniper
#

then you just edit the prefab asset/apply changes to it

jade echo
#

so it looks like there is a prefab of this particular asset

#

But the muselist is empty

#

so then am i boned lmao

#

if the prefab isn't being used anyway

#

like i need to go back to make changes to every single scene

#

wait i misspoke

tranquil juniper
#

you would need to add an instance of the prefab to the scenes yes and then update references to the new object

#

sucks that whoever made this before did not think ahead 😐

jade echo
#

this has made me want to tear my hair out i swear to god

#

lmao

#

is it possible to make same change in multiple places?

#

somehow

#

i know that messing with the underlying yaml is probably no no

#

but could i?

tranquil juniper
#

you can automate it with some code. you can open scenes, modify the scene, set it as dirty, save and close the scene

jade echo
#

To close the loop on this, I ended up figuring it out

#

I just had to make the same change to modify the list in 26 different places

#

Nothing more complicated than that

#

but ughhhh

latent sable
#

so when you need to change the list again you only need to do it in one place

jade echo
#

I didn't

#

But i should've

#

I needed to make a quick and dirty fix because my collaborator was waiting