I’m very new to scripting. I can do your basic operations and I could do what I’m trying to do in a very inefficient fashion, but there must be a better way.
I’m creating a script that will be attachable to rigidbody objects that will monitor physical properties of that object by relative coordinate systems. For example, it will record velocity, acceleration, impulse vectors relative to an arbitrary down vector or relative to other objects in the game world with the same script. The problem is, I’m aiming to make this script extremely versatile, wherein I’d like to incorporate it into more than one attempt at a first game. Because I want to make it, potentially, possible to attach this script to 10,000+ objects, it’s completely unreasonable to perform all these vector functions in the same frame for all 10,000 objects. Hence, I need a script manager that prioritizes and manages updates for each object.
My goal is to have an empty object in each scene with the script manager attached. Each individual script will register with the script manager and be assigned an ID number and the script manager will then decide which script gets priority and how often its internal data is updated. This is where my problem lies.
My instinct as an amateur is to create in the script manager a class for each script which will manage the priority and ID number of the script. This isn’t particularly hard unless you have to unregister scripts, for example, if an object is destroyed, the script manager needs to be told that it doesn’t need to worry about that script anymore. When I delete a class object from the array, the array index of all the other class objects will change, which will make it difficult to manage the ID numbers of the scripts. I don’t want to sort through the entire index of 10,000+ class objects in search of which object to destroy - there must be a more efficient way to do this.
In short, I want my object, we’ll say “Ball” with ID Number “10005” to just tell the script manager “unregister number 10005” and I don’t want the script manager to sort through 10,000 objects to find that ID number - nor do I want to assign new ID numbers to every class object in the script manager’s registry every time one of them unregisters.
Like I said, I’m pretty new at this stuff, so there’s probably a great way to keep indexes of objects that are easily accessed that I’m just not aware of.
I’ve considered making the script manager just take the total number of registered objects, say 10,000. Then keeping track of “halfway” points. So, it knows that 10,000 objects were registered. It knows the half-way point is 5000. So, at Array Index 5000 should be Object ID number 5000. But object 900 and object 1045 just unregistered. So, now there’s a total number of 9998 objects, the halfway point is 4999 and at point 4999 the Object ID is now 5001 so any object ID over 5001 only has to search through the latter half of the class object array. This subdivision technique could subdivide multiple times which would make searching the array much faster - but I just don’t know if this is the best technique.
I hope this makes sense and nobody is getting too much of a laugh out of my programming ignorance.