x


DeleGates And Events

Hi,

I am using a delegate/ event in my script in a scene called level1. In the scene Level2 i use the same scripts with the delegate / event in there.

My question is does the subscriber in the last loaded scene still subscribe to the event and cause it to run the code 2 times?

If i run each scene by its self it all works. If i run the scenes after each other the delegates run 2 times.

How do i unsubscribe to events before i load the next scene?

Thanks

more ▼

asked Jan 25 '12 at 10:31 PM

markpollard gravatar image

markpollard
31 4 5 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The eventmanager or eventlistener may have been loaded twice.

Check if u have used DontDestroyOnLoad function.

more ▼

answered Mar 04 at 10:56 AM

hotshot03 gravatar image

hotshot03
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

If the object is still loaded, it is still subscribed.

-= is the syntax for unsubscribing.

http://www.youtube.com/watch?v=N2zdwKIsXJs is a very good resource for using Delegates and Events.

more ▼

answered Jan 26 '12 at 12:36 AM

kevork gravatar image

kevork
415 1 2 4

Yeah i put debugs in that and its connecting and releasing ok seams there is a bug else where

Jan 28 '12 at 11:02 AM markpollard
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x47
x10

asked: Jan 25 '12 at 10:31 PM

Seen: 1431 times

Last Updated: Mar 04 at 10:56 AM