Creating an NRaas project Creating object with custom script ingame with CreateObjectOutOfWorl method

Talk nerdy to us here.
icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Creating object with custom script ingame with CreateObjectOutOfWorl method

Post by icarus_allsorts » March 18th, 2014, 2:18 am

I posted the following question in the simlogical forums a while back but haven't gotten an answer. Wondering if anyone here has any opinions as to what my problem could be?

I'm working on an interaction that calls for a custom object to be created when it's run. The interaction itself runs properly until the point it tries to create the object where the creation process fails and the sim is reset with the following error:

System.NullReferenceException: GlobalFunctions.CreateObject: Object was created but unable to get proxy. Possibly the medator instance is specifiying a script that does not exist. Resource key for created object was 319e4f1d:38000000:000000000098a4f1, guid was 0x90e3006048c91b30

I'm using the CreateObjectOutOfWorld(string, ProductVersion, string, Simulator.ObjectInitParameters) method where (from my own understanding) the first string is the instance name of the object I want created, ProductVersion its Product Version, the 2nd string the script class I want the created object to have and the last parameter I left as null. I'm trying to create an object in game but with a new custom class (inheriting from the base class of the original object) and have tried different versions of the CreateObjectOutOfWorld method but all of them have errored out so far.

I've even tried cloning the object and giving the cloned object a new instance name in the OBJD resource and changed the script class in the OBJK to the custom script class I want used, but CreateObjectOutOfWorld still fails to create the object with the new instance name specified. Is there something I'm missing here or something else I need to do for this to work? Any help or thoughts will be greatly appreciated.

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » March 18th, 2014, 10:00 am

All I can tell you is that a script is found, since the ObjectGuid is not returning invalid, or you would have seen a failure message instead of the one you're seeing.

From the look of it, it's as if the object was not initialized correctly, either OnLoad() or OnStartup() method in its class might be missing something, check if everything's in order there or if in doubt paste the code here and we'll see :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » March 18th, 2014, 10:14 am

Forgot also the OnCreation() method, that's actually the most important XD

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 18th, 2014, 10:21 am

Thanks for the reply. I didn't override any of those methods (nor the OnCreation() one) in my custom class so it should be using the ones it inherited

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » March 18th, 2014, 10:56 am

It would help knowing more though, what object we are talking about, what object it's inheriting from, what you put as the scriptClass, etc..., the more details the better

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 18th, 2014, 11:20 am

Okay, it's been a while since I've touched the project and at the time I was experimenting with a few different classes (none of which worked) so lemme go refresh my memory for a bit...

But basically, I'm trying to make an interaction for sims to bring Potions made on the Generations Chemistry set to other sims to drink. Problem is the Potion class object isn't "carryable" by sims, so I thought of creating a dummy bar glass for the sim to carry when the interaction is run and the sim will pass the dummy glass to the other sim to drink. But that's as far as the interaction can go so I need to pass the information of the potion along with the glass to the sim who drinks it.

So I've tried creating my own "MixDrink" class, inheriting from the Bar.Glass class, overriding the PushDrinkAsContinuation(Sim) method to run the effect of the potion when drunk. But like I described the error will occur with this line:

MixedDrink glass = (GlobalFunctions.CreateObjectOutOfWorld("GlassBar", typeof(MixedDrink)) as MixedDrink)

Before that I actually cloned the Bar Glass object, gave the cloned object a new instance name as well as the "MixDrink" object class and tried the above method with the new instance name as the first parameter but still no go.

Then I think finally I tried rewriting the custom class to inherit from the Potion class and IGlass interface class and tried creating a potion object instead of a bar glass object with the new class but again no go.

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 18th, 2014, 11:22 am

Oops, they should all read "MixedDrink", sorry about that. My namespace is Sims3.Gameplay.Objects.HobbiesSkills.icarusallsorts since I read somewhere that to create a new scripted object the namespace has to start with Sims3.Gameplay.Objects, if that's of any consequence

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » March 18th, 2014, 11:54 am

The scriptClass should be the fullname of the type, i.e. "Sims3.Gameplay.Objects.HobbiesSkills.icarusallsorts.MixedDrink" or whatever is the fullname, but using the other method where it requires the string. I'm not sure whether it differs from your approach, if the cast is being effective, but it might be worth a try :)

I never needed this in my mods so it's a new territory for me, but personally I would go with a new object (inheriting from GameObject and all the necessary interfaces) and write it from scratch. But even doing this, you say you get the same exact error? Or do you get something different?

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 18th, 2014, 12:22 pm

I've tried both typing the full name of the type and using typeof(MixedDrink).FullName in the method that needed the string before but same error. I could try the completely new object approach and see if it works later though I kind of want to avoid it if possible since I'd rather focus on the interaction itself.

If the object still refuses to create, I guess I'll just have to do without it and just have my interaction push the 2nd sim to drink the potion on his/her own will, which at least follows EA's prank system ("ooo, a woopee cushion set for me? Lemme go sit on it!")

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » March 18th, 2014, 12:34 pm

Ah I thought you already tried that, I must have misread something. Well then yes, give it a try before resorting to the alternative.

Good luck with it, I wish I could help more but hopefully someone else will join too, as I'm no expert with object creation ;)

Post Reply