Is there a way to determine the prefab that was used to create an object?
No, but what I do is… inside my instantiated object, on its control script, I have a var called myOwner, that I set when I instantiate the object.
Example:-
var item : Transform = Instantiate(prefab, pos, rot);
var cScript = item.gameObject.GetComponent("controlscriptname");
cScript.myOwner = transform;
This is the way to pass anything you need to at the point of instantiating the prefab.
Note “myOwner” will get busted if the scope of the owner fails, as in the owner transform is Destroyed();
Thanks for the suggestion. I got to playing with it and figured out I could chop the (Clone) off the end of the object name to get the prefab name.
It will probably return to bite me at some point, but it’s very simple
String manipulation like that is more pricey, performance wise, than storing a reference to the creator object - I’d generally recommend Seons approach. However if you’re happy with your solution and you are not doing that string manipulation very often (like every # frames), you should be good.
How about adding a tag to the objects, depending on their origin?
That would work, but I wanted to leave the tags for the game logic. I don’t think the strings will be too much trouble, as they will only be used when a network object is instantiated, which amounts to maybe a couple hundred times when a client connects.
I am using RPC to replace Network.Instantiate, because it is buffered and Network.Destroy is not. Someone offered a solution to that that involved buffering the destroy calls myself, but the server will be running for weeks at a time, instantiating and destroying thousands of prefabs, and I don’t want every client that connects to have to instantiate and destroy everything that went before.
I wish there were a way to remove specific RPCs for objects instantiated on the server. I’m doing an authoritative server, so the clients do not instantiate anything for RemoveRPCs() or DestroyPlayerObjects() can reach.