playMaker

Author Topic: CreateObject not working [Solved]  (Read 4235 times)

izzycoding

  • Playmaker Newbie
  • *
  • Posts: 29
CreateObject not working [Solved]
« on: May 19, 2013, 11:51:16 AM »
Hi,

I am trying to spawn a prefab in my game and it seems that the new gameObject is never created when I test it.
I am using NGUI Sprite for the texture of my object and was wondering if anyone knew of any issues with this that might cause the object to not get created?

Regards,
« Last Edit: May 20, 2013, 03:10:29 AM by izzycoding »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: CreateObject not working
« Reply #1 on: May 19, 2013, 02:03:19 PM »
I'm not aware of any problems with CreateObject. Is the action definitely running? E.g. the state it's on is activated.

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: CreateObject not working
« Reply #2 on: May 19, 2013, 02:44:25 PM »
Turn of the sprite and NGUI texture.

If it works then, it is something wrong with NGUI or the implementation.
If it doesn't work the you made a mistake in your code.

Simple deduction can help narrow down the problem.

izzycoding

  • Playmaker Newbie
  • *
  • Posts: 29
Re: CreateObject not working
« Reply #3 on: May 19, 2013, 03:10:08 PM »
Hey,

Just checked and it is definatley being activated.
Unable to eliminate ngui as without the sprite there is nothing.
Will try by replacing with a cube and see what happens.

Will post back with results when i get a chance to test it.

Regards,

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: CreateObject not working
« Reply #4 on: May 19, 2013, 03:36:08 PM »
Most create object problems I have come from an objects origin/pivot point being off. NGUI might also use really low values like 0.00415 if objects are parented to others that have been scaled down. Also FBX imports from Softimage have problems with "frozen transforms". They look frozen and have everything set to 1, but on importing a value it sometimes changes back to .25 or whatever it was before the object was frozen.

So there can be a lot of problems with your coordinates and scale that makes things behave strangely.

Sometimes it seems in PM, spawning an object on a vector doesn´t happen properly unless you "every frame" it. Timing can have a big influence. Sometimes some actions need a wait "0,01" to work properly. At least the way I "code".

Doesn´t become better through the fact that you can´t see "empty" gameobjects unless you select them. I usually use cubes and turn off visibility instead of using empty GO´s  so a can see their location when they are not selected.

Also pressing "F" to fit an object on the screen sometimes zooms way you out because the parent is an empty with strange transform values. Thus it seems like your object didnt spawn, but actually it is really really tiny.


izzycoding

  • Playmaker Newbie
  • *
  • Posts: 29
Re: CreateObject not working
« Reply #5 on: May 19, 2013, 05:57:11 PM »
Hi,

Ok, I have had a quick play about. The actual object in my prefab is a ready made NGUI UISprite, I did not make this from scratch, although I am wondering if that is maybe what I should have done.

Anyways, I have found that because I am using the NGUI camera for all my entire scene, it seems to screw up the CreateObject. What is happening is that the CreateObject is created in the root of the Hierarchy. Therefore when it is parented to the GameObject I want it under, the whole transform is way off:

Position: x 0, y -2000, z -540
Scale: x 2000, y 2000, z 540

Also it was executing the FSM on this GO which meant if it was outside the camera view it destroyed its self (which for a y position of -2000 was definable happening).

Is there a way to get the CreateObject to spawn at a certain point in the hierarchy? I tried the spawn point and that made no difference what so ever.

Regards,

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: CreateObject not working
« Reply #6 on: May 20, 2013, 01:20:02 AM »
Hi,

 you will need to parent the instanciated object yourself. simply store a reference of it wen you instanciate it and straight away parent it.

bye,

 Jean

izzycoding

  • Playmaker Newbie
  • *
  • Posts: 29
Re: CreateObject not working [Solved]
« Reply #7 on: May 20, 2013, 03:12:32 AM »
Hi,

Thanks, I have just added that and it now seems to be working great. I had to modify the FSM on the sprite to add a ready Listener too.

So what I have now is the GO created, then I set the parent, then I set the position and scale, then I SendEvent "ready" to the fsm of the GO.

Thanks for the help.

Regards,