PlayMaker News > General Discussion

Loosing game object reference

(1/1)

Hexkonst:
I'm trying to create a projectile from a firepoint gameobject that is a child of the weapon.

* Event1
Find Game Object and store to "Firepoint"
* Event2
Create object at "Firepoint"

It stores the reference correctly the first time you play test it, but the second play through the reference is lost and the bullet is spawned from 0,0,0.

Any ideas what's going on?

Thank you!

jeanfabre:
Hi,

 are you trying to reference of an instance in the scene instead of a prefab on the assets folder and in between load a new scene or something? usually reference are getting lost because of this.

 Bye,

 Jean

Hexkonst:

--- Quote from: jeanfabre on April 02, 2018, 03:14:36 AM ---Hi,

 are you trying to reference of an instance in the scene instead of a prefab on the assets folder and in between load a new scene or something? usually reference are getting lost because of this.

 Bye,

 Jean

--- End quote ---

Thank you for the swift answer! :)

I know this limitation of the Unity engine - however, that shouldn't be the case if I use the "Find Game Object" to update the correct reference each play session (if I'm not mistaken). It seems as if the reference is made, but to the old session cached object instead. I'm starting to suspect a bug.

I'm using "Find Child" instead and "Set Game Object" to a global variable. Which seems to solve the problem, but it's still mildly unsettling. :)

jeanfabre:
Hi,

 uhm, maybe you are not waiting for the scene to be loaded properly? waiting a frame might help, are you listening to the callback from the SceneManager for when a sceen is ready?

Bye,

 Jean

Navigation

[0] Message Index

Go to full version