plane icon Welcome to Microsoft Flight Simulator’s SDK Q&A Platform!

You have questions regarding the SDK? DevMode Tools? SimConnect? You would like to submit an idea for future improvements, seek help or exchange knowledge? You’re in the right place.


Please take a moment to read the platform’s guidelines before you get started!


question

Kaiii3 avatar image
Kaiii3 asked FlyingRaccoon commented

SimConnect Event "ObjectAdded" trigger?

When is the SimEvent "ObjecteAdded" triggert? I have tested it with Live Traffic, Offline Traffic (BGL) as well as SimConnect based AI Traffic, but in all cases it was not triggert after a new AI Airplane was added in the Sim.

With the current issue (since SU5) that the Sim can crash when using lagacy (MDLX) models we are currently working on a workaround that will clear the local cache after a new SimObject was added (tests confimred that this is preventing the crash). When adding our Ai Objects va our own tool when can clean the cache before adding them but for a standalone workaround we need to know when the Sim added a SimObject by itself so the cache can be cleared for the next injection.

simconnect
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

FlyingRaccoon avatar image
FlyingRaccoon answered Kaiii3 commented

Hello @Kaiii3

We checked your sample and found out you're not using the appropriate callback.
You need to have a callback for OnRecvEventObjectAddremove, not just for OnRecvEvent

private void Simconnect_OnRecvEventObjectAddremove(SimConnect sender, SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE data)
{
    if (data.uEventID == (uint)EVENTS.SIMOBJECT_ADDED)
    {
        clearCache();
        Console.WriteLine("Clear: ObjectAdded");
    }
}

Regards,
Sylvain

2 comments
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

FlyingRaccoon avatar image
FlyingRaccoon answered FlyingRaccoon commented

Hello.

The AITraffic SimConnect sample is using this event.
I was able to confirm it works with SimConnect based AI and LiveTraffic but I would assume it also works with offline traffic as well.

Did you check that sample?

Regards,
Sylvain

5 comments
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Kaiii3 avatar image Kaiii3 commented ·
The sample is in C++, my Code is in C#. Will give it a go later the week.
0 Likes 0 ·
bert.laverman avatar image bert.laverman Kaiii3 commented ·
You could take a look at CsSimConnect then...
0 Likes 0 ·
Kaiii3 avatar image Kaiii3 commented ·
Hey,


I ran the C++ sample and it worked. Running my project alongside did not trigger the C# SimConnect Event. I will send you the C#-Project.

0 Likes 0 ·
DA40CGDFQ avatar image DA40CGDFQ commented ·

SDK update 20.3 still does not have the ObjectAdded and ObjectRemoved SystemEventNames.

are there any other eventnames not show - Search does not find anything.

da40cgdfq-20221103-11h18m48s-26.png

0 Likes 0 ·
FlyingRaccoon avatar image FlyingRaccoon ♦♦ DA40CGDFQ commented ·
Hello @DA40CGDFQ

They will be added by @Nocturne
Regards,
Sylvain

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 19.1 MiB each and 23.8 MiB total.