Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I just thought I'd come back here to mention - I've made a few discoveries of my own. I'm still trying to pin all of them down, but the big one I've found is that although you can't serialise C# collections using [Export], provided they are initialised as null they're fine to use as a field in a plugin. You can Export access to a cached Godot collection as well - the getter for the Godot collection can instantiate the C# collection, effecting serialisation without throwing an error (unless something else asks for the C# collection *before* the Godot collection is requested, obviously - so this may necessitate some null checks you wouldn't otherwise use). I've used this outside Editor plugins just for the convenience of using C# collections, and was pleasantly surprised to find the same method works in this context.

ohhh, that is very astute, I would have never thought of doing that. Although, I am wondering which C# collection you are using that is worth having all this extra boilerplate code?

I'm self-taught, only ever learnt C# (and a little C/CPP), work alone, and only been programming for 5-6y - so I will often do things in bad, wrong, or stupid ways, depending on what seems to work. Take anything I say with a hefty slab of salt.

My current thingamajig is a node that manages a fairly big queue - not using a Queue collection as a fundament seemed silly, and Queue/Dequeue operations on large collections are very fast compared to the equivalent ops on an array. I don't need serialisation, so all I do is initialise the collection as null, assign it during '_Ready', and I can depend on it being available for the remainder of operations without throwing any untraceable errors. 

It's not *too* onerous in terms of boilerplate if you *do* want serialisation; something like what's below does the majority of the heavy lifting, you've just got to assign cached_Vecs using queue.ToArray() at some point.

[Export] Vector3[] serialised { get{ queue ??= new(cached); return cached; } set{} }
[Export] Vector3[] cached = Array.Empty<Vector3>();
Queue<Vector3> queue = null;