Handling Array properties in Cocos Creator

Hey guys, so here’s the deal:

There are multiple nodes on Canvas each has a custom component with script Node.ts


Nodes have various amount of neighbours (let it be from 2 to 4)

So what I want is to customise each node with amount of its’ neighbours like this:
45

The properties in Node.ts are like this:
@property([cc.Node])
neighbors: cc.Node[] = [];
@property([cc.Vec2])
validDirections: cc.Vec2[] = [];

The trouble is each time I bind a neighbours in Cocos Creator, when I select another object it removes all the properties except the length, like this:

01

So I really don’t get it how to make it static and save the values inside the node
What am I doing wrong?

anybody? :face_with_raised_eyebrow:

I couldn’t understand what you mean with binding neighbour? Can you say what are the steps?

Hey there, thanks for response.

Here’s an example in Unity:
example

We have nodes in (x,y) space. Each node has a custom component (Node.ts) on it.
I want to make paths between them, so I define which of them are neighbours.

I set up a property: N size array where each element is cc.Node
Then, in Cocos Creator, I drag each node as an element of N size array.

In Unity, there’s no need in any extra steps, it just remembers which nodes were dragged into array.

In Cocos Creator, however, the only length of array is remembered. Each time I switch between elements in canvas, everything that has been dropped into array erases.

I wonder how can I save these nodes inside of an array.
I guess it requires some extra scripting of me, but I really don’t get it how to handle the nested values (elements of an array).

1 Like

I couldn’t reproduce the problem.
I can easily switch between nodes and all values remain as I set before:

ss_properties

I think there is something resetting values in your script.

1 Like