C# object destroys reference to string ( I think)
Posted 28 November 2011 - 11:04 PM
I have a string which acts as a caption and disappears after a certain amount of time.
I get the string from a game object script which has a string in it so it looks something like
Everything works fine unless I destroy the object right after I get that caption. Then it disappears. I assume this is because anything referencing the object destroyed gets destroyed also or loses reference. I looked around on c# and they have a copy method which supposedly creates a new instance, but same thing happens. So, does anyone know how I could keep from losing that string?
EDIT: Nevermind. There's something weird going on because I can use setCaption("a string"); and the same thing happens when I call the object to be destroyed.
Posted 29 November 2011 - 02:23 AM
Posted 29 November 2011 - 02:33 AM
I haven't looked into that, no. Not sure how it would align with Unity's GUI system. I think I'm referencing the object in another place in the program and that's what's causing the problem when I destroy it. I should have known because things were going too easy.
Posted 29 November 2011 - 03:13 AM
Posted 29 November 2011 - 03:44 AM
It was in another part of the program where a feature tested for a null after a ray cast and set the caption to nothing if it found one. When I deleted the object, it found a null. I kind of forgot about it. One was doing a mouse-over, one was doing a mouse-click when it was over something. It all worked fine until I deleted an object. The setCaption is my own function and I'm sure worse than anything Microsoft could imagine. Unity code is pretty weird though, to my way of thinking. The GUI is the strangest I've seen but it works all right. Not the most object oriented code around. You don't need much GUI for a game, some buttons and labels.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users