Hallo, and guten morgen
Can anyone spare how i can modify the pointers reference?
I have looked into System.Reflection and i think i need to go through there, but im not familiar with this NameSpace, and id like a little help.
My summary of events:
I have an object: A ; There is an object B that references object A ; If i exchange object A with another object (object Q), how can i manually modify the references to object A and tell it to point at object Q.
From what i read in the Reflection NameSpace, i believe i can modify pointers manually. Im reasonably new coding (around 1 1/2+ years) , so im hoping someone with more experience can give me an example of this implementation.
In the reflection class there is Pointer, as i understand:
Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Is Unity the immediate caller or am i (the unity user) the immediate caller? Can i access pointers path directly through Unity, or do i need to make a plug-in to directly mingle with the .Net framework. I want to establish myself as the caller so i may switch the references myself.
What is the best way to make this exchange: -object A- to -object Q- ?
asked Aug 18 '12 at 06:16 AM
For some reason it took me a while to understand what's your problem. Here's what I get:
You have a gameobject Master that references a gameobject Slave. You created a script that deletes Slave and replace it by Clone - but Master never hear about this, so it start throwing NullReferenceException everytime it calls something on Slave/Clone. From what I read, you also plan to redistribute the system, which let me think you cannot assume anything about the project.
AFAIK, there's no standard way to handle this. I don't know of a way to trace all references to an object - especially not in a managed environment, in the Unity context...
I don't think Pointer are of any help here - and anywhere really. I might be biased, but my understanding is that managed languages does its best to make sure you never have to do any risky stuff. Let the proven environment handle your garbage and your pointer stuff, also 'unsafe' sounds bad.
Reflection might get you somewhere, but I'm afraid it'll be painful and very inefficient to reflect, loop through, find and hold relevant references from all the projects' classes. I'm not even sure if that would work really, I haven't used it often.
If I was you, I'd first try to modify my script so it never deletes the gameobject in the first place, if the system is a mesh merging one, couldn't it just modify the mesh and renderers, instead?
In C#, you should not have to deal with pointers when using Unity unless you are doing something very complicated and out of the box (and even that I do not believe is possible). C# allows for pointers but the code is required to be marked 'unsafe.' Unity restricts unsafe code. I doubt this is what you need though. What is the type of the object you are working with? This matters because most value types will be structs (Vector2, Vector3, Color, etc) which are all handled by value. So when you do an assignment, it doesn't reference the original object; instead it copies the contents over to the new structure. You can get around this in certain instance with methods using (out and ref) but these are only temporary. There use is primarily so you can change more than one return value of a method.