FlowCanvas Forums › Support › Spawning/destroying multiplayer objects?
I’ve already asked this on the flowcanvas Unity forums topic, but would like to ask here too in-case it’s more visible about spawning/destroying multiplayer objects.
The only 2 methods I could find hunting through the actions and reflections with flowcanvas were create object and instantiate object, however though I had a network identity on the objects they never seemed to show up on the client.
Is there some method of connection or action I’m meant to take to properly enable these to be created and destroyed smoothly across all connected games? I’d greatly appreciate knowing a way to get this all working.
Hey,
To spawn network objects and destroy them as well, you should use the special Network.Instantiate and Network.Destroy methods (of the Unity Network class). To make them show in FlowCanvas, please add the Network type in the Preferred Types Editor list and then you will be able to use all Network class methods and properties 🙂
Let me know if that works for you.
(PS: The new version will have a search field for the Preferred Types Editor)
Join us on Discord: https://discord.gg/97q2Rjh
Just to clarify 🙂 To open the Preferred Types Editor, please navigate to “Tools/ParadoxNotion/FlowCanvas/Preferred Types Editor”, then click “AddType” and find the ‘Network’ class under “Classes/UnityEngine”.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Thanks a lot for your responses 🙂 saw your one on Unity too and the image helped me confirm I was using the right methods.
I responded there but I figure in-case this line of questioning continues too much it would make more sense to just keep everything here, so this is where I’ll continue to respond regarding this :). Here’s what I posted there on the issue:
I was able to find it thankfully, however I’ve run into an issue where it’s saying “Failed Network.Instantiate because we are not connected.”, even though I’m functionally able to even connect clients to the server using Unity’s network manager HUD and have players instantiating via scripts from another plugin, and even looking at the object with the flowcanvas to instantiate the object, its networking information says yes for IsClient/IsServer/IsAuthority.
Hey,
Very sorry for the late reply.
So, totally my bad, because the Network.Instantiate method is of the old/legacy unity network system. :/
The new system uses the ‘NetworkServer.Spawn’ method. Taken from the Unity manual here: http://docs.unity3d.com/Manual/UNetSpawning.html …
…this flowscript should work, although I didn’t test it yet (will do as soon as possible):
The variable ‘myGameObject’, as per the manual link above, must has a NetworkIdentity component and must also be registered in the NetworkManager “Spawnable Prefabs” which can be done though the inspector of NetworkManager.
Unfortunately the NetworkServer type would be a bit of a pain to add right now through the Preferred Types Editor, as it resides at the very end of the ‘Add New Type’ menu and under “Classes/UnityEngine/Networking/NetworkServer”.
The new version soon to be released, has a new search field for types instead of going through all this menus though 🙂
Please let me know if the above works for you, and I will also post back when I get to try this one.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
No worries, thanks so much for the thorough response :)!
That, is definitely closer :D, it spawns the object which is great-however, it first instantiates the object too. I’ve tried a bunch of variations of setup but even without calling the instantiate when it’s connected to the spawn function it creates a clone, so it’s spawning 2 objects each time instead of just the clone and I can’t find any way to save the spawned clone as a blackboard variable which I need to be able to do. Also the examples in that manual seem to use GameObject to instantiate instead of UnityObject, when in flowscript the only way to get to instantiating at the game object level is by making an action and you can find that method in there (doesn’t exist in the reflect branch?).
Looking forward to more search fields :D.
Hey,
The Instantiate method is a static method of the Object type. The example code in the manual calls it from GameObject, because GameObject derives Object. The Instantiate method, always returns a type of Object. If you see the example code in manual, the method return value is cast to GameObject with the parenthesis. This is exactly what we also do in the flowscript with the ‘Cast To (GameObject)’ node 🙂
If you want to store the instantiated object to the blackboard, that object would be the return ‘value’ of the ‘Cast To’ node output. This value is the new instantiated gameobject, which you can do whatever you like it.
I am not sure what you mean by spawning 2 clones though 🙂 Is it possible at all to send me a small project (support@paradoxnotion.com) to see what you do and how you set it up as a whole?
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Ahh thanks for explaining that, being unfamiliar with how that worked I didn’t realize it was being cast to it like that :).
Appreciate knowing that’s how it should work, though the project I sent you may show why I wasn’t able to have that work for me ^^;
Yep I was able to send you a barebones reconstruction of the issue to that email so hopefully it helps work things out, thanks a lot for the support :)!
You are welcome 🙂
I’ve replied to your email a moment ago by the way.
Let me know if that works for you.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh