DeMaCS-UNICAL / ThinkEngine

A Unity asset for a tight integration of AI in games: asset, showcase, web page.
19 stars 1 forks source link

Unexpected behavior when property becomes null #24

Closed deniseAngilica closed 1 year ago

deniseAngilica commented 1 year ago
          In my case, I had a simple class:
[Serializable]
public class KitchenObject
{
    public string Name;
    public int ID;
    public int ContainerID;
}

and inside a script

public class KitchenObjectContainerSensorData : MonoBehaviour {
    public KitchenObject FirstKitchenObject = null;

     private void UpdateData() {
         ...
         if (HasAnyKitchenObject)
             FirstKitchenObject = new KitchenObject(...);
         else
             FirstKitchenObject = null;
         ...
     }
}

all the properties inside KitchenObject are meant for ASP encoding, on game start the FirstKitchenObject is null and will be like that until the player picks up something. At that point, the values will be updated and reflected in the input files in this way:

Game start:

MISSING s_Player_FirstKitchenObject_ContainerID
MISSING s_Player_FirstKitchenObject_ID
MISSING s_Player_FirstKitchenObject_Name

Few frames after Game start:

s_Player_FirstKitchenObject_ContainerID(player,objectIndex(1),0).
s_Player_FirstKitchenObject_ID(player,objectIndex(1),0).
MISSING s_Player_FirstKitchenObject_Name BECAUSE OF EXCEPTION

FirstKitchenObject assigned:

s_Player_FirstKitchenObject_ContainerID(player,objectIndex(1),-2490).
s_Player_FirstKitchenObject_ID(player,objectIndex(1),-6178).
s_Player_FirstKitchenObject_Name(player,objectIndex(1),"CheeseBlock").

FirstKitchenObject unassigned:

s_Player_FirstKitchenObject_ContainerID(player,objectIndex(1),0).
s_Player_FirstKitchenObject_ID(player,objectIndex(1),0).
s_Player_FirstKitchenObject_Name(player,objectIndex(1),"CheeseBlock").

as you can see after being assigned and unassigned, in the input files, the Name is still assigned the previous value

Originally posted by @Farfi55 in https://github.com/DeMaCS-UNICAL/ThinkEngine/issues/22#issuecomment-1657996063

deniseAngilica commented 1 year ago

@Farfi55 if i got it right, the problem here is that when the property becomes null, input continues to have previous value, am I right?

Farfi55 commented 1 year ago

Yes, that's what seems to be happening

deniseAngilica commented 1 year ago

@IlDirettore95 what does it happen when a property is null? If I'm right the null value is added to the values list, right?

IlDirettore95 commented 1 year ago

No. Here is an example of a string property from an Example class

image

deniseAngilica commented 1 year ago

well, I think that adding the null value will resolve the problem: in the current version, if the operationResult is null Map() returns an empty string; being the last value of "values" null, operationResult will be null and everything will work fine. Can I assign this issue to you too @IlDirettore95 ?

IlDirettore95 commented 1 year ago

No problem, i got this! So there's no problem if operationResult is null? As far as I know Map() method will throw an error.

deniseAngilica commented 1 year ago

Yes, I added a fix few minutes ago, if operationeResult is null, Map() will return an empty string. Let us know when you're done, thanks!

deniseAngilica commented 1 year ago

Solved by removing streams of null properties and no more existing collection elements.