Answer the question
In order to leave comments, you need to log in
Problem with FindObjectOfType with Instantiate. Why is more than one object created?
Guys, Problem with FindObjectOfType c Instantiate.
there are two classes in class1 calling a method on instantiate object creation in class2 . All classes on different objects. I call through FindObjectOfType The problem is that in this case, not one object is created for me each time, but multiplied by the number of created ones (1 * 2 * 4 * 8, etc.). Who knows what the trouble is?
https://pastebin.com/MnK0VAse
Answer the question
In order to leave comments, you need to log in
Most likely, you are calling the creation function on each object, which is why it multiplies.
FindObjectOfType().Respawn(); You after all cause creation on all objects of type SpawnerFigure. If 10 then each will create an object.
If you are using the singleton pattern, this will cause similar problems if not configured correctly. The object of the previous scene is not deleted, but a new object is additionally created, the same as that specified in the scene.
you would attach screenshots of the inspector and the scene hierarchy in order to know what you have there on the instantiated objects and what is in the scene.
so, judging by the fact that each time more and more is created, then the FigureSwitch script hangs somewhere on the object being created.
and on one key press they react, first 1, then two, then 4 objects).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question