[ANSWERED] How does creating objects with weapons interact with callback OBJECT ADDED?

Any issues, problems or troubleshooting topics related to the additional features present in the Prepar3D Professional Plus client application.
minime
Posts: 1198
Joined: Mon Jun 10, 2013 4:33 pm

Postby minime » Thu Jan 09, 2014 5:28 am

To me it seems that if I create an SA-2 launcher I am actually creating at least TWO SimObjects, the launcher and the weapon (and maybe the pylon as well).



But I am hooked into the OBJECT ADDREMOVE callback:



conn.OnRecvEventObjectAddremove += simconnect_OnRecvEventObjectAddremove;



and I am only getting a call for ONE object that is created.



Even if I now shoot the weapon from the launcher (which actually should have its own SimConnect function), there is neither a call to OBJECT ADDED nor to any of the new weapons callbacks.



I do need the ObjectIDs of the weapon as well, how can I get them and why does the callback only fire once if I create two objects?


Adam Breed
Lockheed Martin
Posts: 1385
Joined: Mon Sep 20, 2010 6:17 pm

Postby Adam Breed » Mon Jan 13, 2014 3:30 pm

Hi minime,



Do you get the AddRemove callbacks with weapons that are attached to the user? Using the AITraffic SimConnect sample, I do get the AddRemove callbacks for the weapons:



AI object added: Type=6, ObjectID=44



In your case, each object has an ID and they are two SimObjects, so you should get a callback for each.
Prepar3D® Engineering Project Manager

minime
Posts: 1198
Joined: Mon Jun 10, 2013 4:33 pm

Postby minime » Mon Jan 13, 2014 5:25 pm

Yes, I get the weapons for the user weapons when I shoot them.



I do not get them for any weapons that are attached to SimObjects.



So the idea is that although the weapons are already in the world, the OBJECT ADDED actually happens when you disconnect them from the object?



I think I should be able to work with this. I just have to find a different way of getting information.



Thx.





Minime

minime
Posts: 1198
Joined: Mon Jun 10, 2013 4:33 pm

Postby minime » Fri Jan 17, 2014 8:18 am

Ok, now I put in tons of debug code, and I mean tons, so I see what is going on better. So how it works is this:



- When I create an SimObject with weapons, first all the weapons and rails are added and then the SimObject. (before I did not see that cause of the way the debugging code worked)



So you are correct, everything works as it should right there.



The catch is that you only get the OBJECT ADDED but not the ASSIGNED OBJECT ID which is why my code was not showing it to me as it hides objects without a valid ID. So now I am also grabbing the objectID from the ADDED callback. So yeah, you only get the ASSIGNED OBJECT ID if you actually create the object yourself, not for objects that are created for you.



- Now the weird part is... when I shoot, it happens again, all the weapons are added again and the SimObject as well. (I did see this, I just did not realize they are added twice)



I do not know why that is, but based on the complexity of the software it's probably a bug I introduced some time in the past. So I will try to fix that and it hopefully is not Prepar3ds fault.



So, this seems to be how it works, in case someone finds it useful.



Thx!



Minime

Adam Breed
Lockheed Martin
Posts: 1385
Joined: Mon Sep 20, 2010 6:17 pm

Postby Adam Breed » Fri Jan 17, 2014 10:25 am

Hi,



If you have more than one weapon per-hardpoint, a new one is created right when the other is fired. That could be what you are seeing. For realistic training, each station hardpoint would likely only have one weapon and they would not be reloaded out of thin air, so if you have 1 per-hardpoint, I don’t believe you would see the weapon added again.
Prepar3D® Engineering Project Manager


Return to “Prepar3D Professional Plus Client Application Questions”

Who is online

Users browsing this forum: No registered users and 9 guests