Hi there,
I got the following problem. I instantiate an item from an inventory which has the destructable saver and position saver on itWhen I leave the cube (which already is present in scene 1, so it is not being instantiated and it has named keys, see screenshot) in scene 1 and move from scene 1 to scene 2 to using a portal, and return to scene 1, the cube is where I left it. When I go to scene 2 and instantiate the cube (a prefab with the same components, but with no named keys) from my inventory and leave the cube there, go to scene 1 and back to scene 2, I now have the problem that the cube is gone. I think this is because the prefab does not have named keys assigned to it, causing conflicts with other instantiated cubes. Is there a way to assign random keys after instantiation? Maybe I only need to randomize the name of the cube, since a blanc key takes the gameobject name. But how do you do that after instantiation? I tried using Start(){gameObject.name = "Item" + Random.Range(1, 9999999999999999).ToString() + Random.value.ToString(); } in a script attached on the prefab, but this does not work, probably because Start() is invoked again when re-entering the scene and the name/keys get randomized again... So that would mean that I would have to find a way that the name is only set once... Am I thinking in the right direction? Any thoughts?
Kind regards,
Stefan
random key or gameobject name for destructable saver / position saver
-
- Posts: 29
- Joined: Fri Jul 17, 2020 9:19 am
random key or gameobject name for destructable saver / position saver
- Attachments
-
- Capture1.PNG (33.76 KiB) Viewed 651 times
-
- Posts: 29
- Joined: Fri Jul 17, 2020 9:19 am
Re: random key or gameobject name for destructable saver / position saver
Hi Tony,
I removed the position saver and destructable saver from the prefab cube and added the spawned object component to the prefab cube and I added a spawned objects manager in both scenes. When I now take a cube from my inventory and drop it on the floor (i.e. the cube is instantiated) in scene 1 and move to scene 2 using a portal, there is a cube in scene 2 on the exact spot that it was in in scene 1. Enabling/disabling the position and destructable savers in various configurations does not seem to have an effect. I updated Dialogue System for Unity just in case, but this does not solve the problem.
Any idea?
I removed the position saver and destructable saver from the prefab cube and added the spawned object component to the prefab cube and I added a spawned objects manager in both scenes. When I now take a cube from my inventory and drop it on the floor (i.e. the cube is instantiated) in scene 1 and move to scene 2 using a portal, there is a cube in scene 2 on the exact spot that it was in in scene 1. Enabling/disabling the position and destructable savers in various configurations does not seem to have an effect. I updated Dialogue System for Unity just in case, but this does not solve the problem.
Any idea?
-
- Posts: 29
- Joined: Fri Jul 17, 2020 9:19 am
Re: random key or gameobject name for destructable saver / position saver
Never mind, I solved it. Turns out I had to give the Spawned objects manager in scene 1 a different key than the key of the Spawned objects manager in scene 2 (a different name of the gameobject that has the spawned objects manager might work as well?). This step is maybe missing from the documentation? Any way, this works for me. Thanks once more.
Re: random key or gameobject name for destructable saver / position saver
Hi,
Thanks for pointing that out. I'll add that note to the documentation.
Thanks for pointing that out. I'll add that note to the documentation.