playMaker

Author Topic: Mouse pick event Error importing an UI prefab [SOLVED]  (Read 1736 times)

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Mouse pick event Error importing an UI prefab [SOLVED]
« on: January 22, 2018, 03:11:29 PM »
Ive done my inventory system in a separate scene and save it as a prefab.
When importing it into the main scene, ive got this error from all the objects using the MousePick2 action.

NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.Actions.MousePick2dEvent.DoRaycast () (at Assets/PlayMaker/Actions/Physics2D/MousePick2dEvent.cs:103)

Am i doing anything wrong?
« Last Edit: January 30, 2018, 11:34:13 AM by miguelfanclub »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse pick event Error importing an UI prefab
« Reply #1 on: January 23, 2018, 01:34:02 AM »
Hi,

 You are likely referencing a scene Object from the prefab, and it's something Unity doesn't allow. So when you instanciate that prefab it doesn't have that reference anymore.

 You need to plug scene object reference on the fly after you created a prefab instance, either the instance finds what it needs in the scene or you have some sort of manager ( for example the fsm that created that prefab instance), and it inject directly the reference needed to the newly created instance.

 Check out the Ecosystem sample "Prefab Instantiation" for a working example, it features some ways as explained above.

Bye,

 Jean

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: Mouse pick event Error importing an UI prefab
« Reply #2 on: January 23, 2018, 03:50:47 PM »
I see. but its weird as im not calling anyone from the prefab, just game objects that are inside.

That scene is full of compiler errors. Ill keep looking.

thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse pick event Error importing an UI prefab
« Reply #3 on: January 26, 2018, 02:01:41 AM »
Hi,

 ok, let me know if you can't get anywhere.

 Bye,

 Jean

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: Mouse pick event Error importing an UI prefab
« Reply #4 on: January 30, 2018, 11:14:26 AM »
In case is useful to anyone:

So the problem was that importing a prefab that contains a canvas into a scene doesnt create an event system. What I did is create a new canvas in the scene, then  Unity automatically add an Event System and then just delete the canvas. It worked.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse pick event Error importing an UI prefab [SOLVED]
« Reply #5 on: January 31, 2018, 03:46:20 AM »
Hi,

 uhm, thanks for sharing this, yeah, you can waiste a lot of time with this kind of things... :)

 Bye,

 Jean