• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Cannot get the ObjectId ....

Messages
25
I have this issue creating different objects:

in an iteration i have to create some objects and in the same time identify them by their objectId in order to destroy later.

I use :

foreach (DataRow dr in my.Rows)
{

if ( condition ==true)MYDATA.AICreateSimulatedObject(Name, Init, DATA_REQUESTS.MYOBJECT);

if (condition ==false) MYDATA.AIRemoveObject(ObjectId, DATA_REQUESTS.MYOBJECT);
}


This is the issue: when i have 2 or more object to create i cannot retrieve the object ID (i use AssignedObjectId method) :the second object is created before the first ObjectId is recognized ...maybe the iteration is faster than the system response sending me back the ID and the AssignObject isn't triggered.

I solved this breaking the iteration when the first object is created ...wait some time and do the iteration again and again..

THE solution could be to wait in the iteration until the AssignObjectId is really triggered and the Id arrives but i'm not able.
Any hint about?

Thanks
Rob
 
Hi,

Take a look at SimConnect_SubscribeToSystemEvent - specifically the ObjectAdded event. Without trying it I'm not sure how you'd tie this notification to a specific event though - check the EventID (and friends) to see if they match.

Cheers,
Jim
 
Mmmmh ..i tried this:
enum EVENT_ID
{

OBJECT_ADDED,
PAUSE,
};

FSData.SubscribeToSystemEvent(EVENT_ID.OBJECT_ADDED , "ObjectAdded");
FSData.SetSystemEventState(EVENT_ID.OBJECT_ADDED, SIMCONNECT_STATE.ON);
FSData.SubscribeToSystemEvent(EVENT_ID.PAUSE , "Pause");
FSData.SetSystemEventState(EVENT_ID.PAUSE, SIMCONNECT_STATE.ON);

I call a create simobject ..then press the "P" for pause and
In receive event i only get the Pause event ..never the object added.
Something missing?
Thanks.
 
Hi Rob,

What you want to do is use a unique request ID for each call to AICreateSimulatedObject and then hook the OnRecvAssignedObjectId event (this will return a structure that contains the request ID you used in the create call and the object ID that was assigned). Your code needs a way to determine if the object ID for a given item in your list has been received yet (since you need to store the request ID in the item data, you could just use the fact that this field is non-zero, and then reset it to zero once you receive the ObjectID).

something like:

Code:
enum RequestIDs
{
   SomeRequestID,
   AnotherRequestID,

   CreateAIObjectRequestIDBase = 0x00010000,
   SomeOtherRequestIDBase = 0x00020000,
}

private int nextIndex = 1;

...

AICreateSimulatedObject(Name, Init, RequestsID.CreateAIObjectRequestIDBase + nextIndex);
nextIndex++;
if (nextIndex > 65535)
    nextIndex = 1;

Also, you need to keep in mind that SimConnect is designed as an async interface, and you have to design your code accordingly (so you start an operation in one place, store the state data somewhere, and handle the completion of the operation somewhere else, using the stored state data - in the above example, the value RequestsID.CreateAIObjectRequestIDBase + nextIndex would be used as the key to store/retrieve the state data, or you could just use nextIndex by itself I suppose, as long as you did the math correctly in the OnRecvAssignedObjectId handler to match :-> ). Its also a serialized interface, which means if you are sitting in a recv handler for one of the SimConnect events, and you make a bunch of SimConnect calls, you won't receive any of the return data until after your current function finishes.

Standard procedural programming methods won't quite work in this environment :->
 
Its also a serialized interface, which means if you are sitting in a recv handler for one of the SimConnect events, and you make a bunch of SimConnect calls, you won't receive any of the return data until after your current function finishes.

Standard procedural programming methods won't quite work in this environment :->

Thanks for explanation, a very useful lesson!.

Those words explain the reason i cant get the objectId when i throw more than one object but just when i break the iteration.
Thanks again.
Rob
 
Those words explain the reason i cant get the objectId when i throw more than one object but just when i break the iteration.
Thanks again.
Rob

Hi Rob, just a quick question... (so I understand correctly) I do see 'short pauses' when batch inserting via AICreateSimulatedObject, when the iteration ends the sim resumes. the pause period is proportional to the number of objects being inserted, what would be your opinion on this particular matter? why the sim pauses during this iteration?

Thanks,
 
The reason you are seeing the pause is that, while the communication part of SimConnect runs async on a background thread, that just queues the requests to be handled later on the main foreground thread, meaning all your AI objects are getting created on the same (or a very small number of) frame(s). One way to work around this would be instead of sending all your AICreateXxx calls at one time, create a list of the objects you want to create, send an AICreateXxx call for the first one, and in the Receive Object ID callback, send the AICreateXxx for the next item in your list (one per callback) until the list is empty. This way, the creates would be spread over a larger number of frames, and while the framerate will go down some during this period, it shouldn't cause it to halt/pause completely.
 
Back
Top