Hello
Recently bought AC, love it, blazed through manual, but when it comes to practice - I have some hiccups.
For example, in my tests I've noticed that Object:Add or remove doesn't seems like doing what is supposed to do:
Also on slightly different note, when I simulated Add feature on custom script - looks like there isn't actually any way to refer to instantiated objects in Action Lists, only to original object.
So my question: am I dumb or something not right? Because I prefer to be dumb in this situation.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @Gonny.
I'll need a few more details to properly understand your situation. What are your AC and Unity versions? Your AC version is displayed at the bottom of the AC Game Editor window.
You've assigned a prefab in the Action's Object to add field, I take it? Leave the Position relative to field as Nothing for the moment - does nothing still get spawned in?
Is this part of an ActionList asset, or a scene-based ActionList, and when is it run?
If you can spare a screenshot of the Action, and prefab you're trying to spawn, that will help me undertstand the specifics of your situation.
This may be a duplicate of your issue with the Add method - as both rely on the same technique to spawn the requested object into the scene.
Check your Console at the time such Actions are run. The only case in which a supplied prefab is not spawned is if AC has determined that it is already in the scene - but this is only if you've set this up, and the Console will report this scenario.
Can you share the script you're using? I'm not clear if you're trying to spawn an object through script, or merely reference the object spawned using Actions.
If you're looking to have Actions reference a spawned object in the scene, you'll need to attach a Constant ID component to the prefab, and check Retain in prefab? so that its ID value in the prefab matches that of the spawned instance. Actions that reference this prefab will then attempt to find the spawned instance at runtime by searching for the scene object with the same Constant ID value.
AC 1.72.4
Unity 2021.1.0b1 (64-bit) (but I've tested it on the stable version too)
Yes, nothing spawn
This is Action, simple hotspot on Use https://imgur.com/a/FijWn94
This Object, just a sprite to mark the spot https://imgur.com/a/hL2rdfg
I don't see any messages in the console at the moment of interaction with the hotspot
It doesn't look like you've assigned a prefab - its Constant ID value should be listed in the Action if so.
Where is your "TeleportTestMark" located? For it to be spawned at runtime, it must be a prefab - i.e. located in your Assets folder in your Project window, not as part of the scene's Hierarchy.
How can I do it?
For this test:
-I copied "TeleportTestMark" in every folder in Assets and in Hierarchy
-I added Constant ID component to every single copy and checked on Retain in prefab?
Object:Add only allowed me to choose copies on the Hierarchy btw - and still Action don't list ID in itself https://imgur.com/a/tx2Kpw7 nor does it add anything.
At the same time I can Remove any copy of "TeleportTestMark" even without Constant ID(only in Hierarchy though)
I think what Chris said you have to have your "TeleportTestMark" as a prefab.
Click on it in your hierarchy drag it to your project folder and release the mouse.
Then delete the one in your hierarchy. And in your action list https://imgur.com/a/FijWn94 add the one you've just prefabed (the one you dropped in your project folder) When you add it to your actionlist (interaction) ID should be added automatically to the prefab. Or you can just add it yourself prior to adding it to your actionlist.
When you want to remove it, don't assign the prefab straight from your project folder to your action Object: Add or Remove. First drop it again on the screen then from your hierarchy drag it to your action Object: Add or Remove and then delete it from your hierarchy.
This is what I learned from AC 1.50f, to safely remove added prefabed objects from the scenes. Otherwise if you assign your prefab striaght from the project folder to be removed in your actionlist it will remove it for good in your build runtime (but not in the editor run), and you won't be able to spawn that prefab again unless you relaunch your game.
Oh i see, i need to drag object with Id so it start work, ty!
But it looks like it still spawn only once, at Nothing position, no other "Position relative to" doesn't affect it spawn placement.
Maybe something else should be dragged to assets - camera, player, other objects?
The "Object selection" window that appears when you attempt to select an object to spawn is handled by Unity - unfortunately, this doesn't list prefabs, so yes - you have to drag them from the Project window directly.
Can you elaborate on your exact situation here. How many instances of the prefab are you looking to spawn, and where?
Check your Console - AC will report a warning if you attempt to spawn an object that's already in the scene. If this is the case, search your Project window for the script file named ActionInstantiate. Open it up and replace line 207:
with:
If you want to record the presence of these prefab instances in your save-game files, you'll need to make use of the Remember Transform component. Let me know if this is the case and I can advise further.
What specifically are you setting this and the Relative GameObject to? This object needs to be present in the scene - not the Assets folder / Project window.
When spawned, the added object's final position should account for the position of the supplied Relative GameObject - where is this object positioned in the scene?
Thank you very much!
After adding Remember Transform component to "TeleportTestMark", checking on "Save scene presence?" and changing "Linked prefab ConstantID" to anything other than 0 it started instantiate as many "TeleportTestMark" as I ever want to AND every "Position relative to" works.
But now I have a new question - how can I refer to this instantiated "TeleportTestMark"? Their ConstantID is different from one I put in "Linked prefab ConstantID" and it different for every new instance
If you have multiple instances present in the scene, then IDs will have to vary - which mean you can't refer to them in ActionLists.
How you refer to individually spawned items really depends on what it is exactly you want to do. You could rely on a custom script or tag, or place a Cutscene component on the prefab, have it reference an ActionList asset, and use the ActionList Starter component to assign itself as a GameObject parameter used by the ActionList asset.
Please try to describe the situation here, as I can only give general advice otherwise. How do you want to affect your spawned objects?
In general - I want to spawn a piles of animal feed at vicinity of animal trigger, when that happens animal will go to and eat it(removing from the scene), after that it either will go back to starting marker or go to next feed pile, until it hit the trigger for cutscene, that will open path to the next scene.
Right now I get feed spawning, but now I need for NPC to move to the pile. I can't order it to move to the player, cause player should be able to move and place next pile, so my choice is move animal on the instantiated prefab. But I can't refer to the pile in action list, because it doesn't exist yet. And I can't seems to use marker, because marker spawn instantly and animal start to move before feed is on the scene.
Sorry if this confusing.
If you're relying on Triggers, you can set your Trigger to react to objects with a given Tag.
If you give your "feed" prefab a special tag e.g. "Animal feed", then go to your Animal's Trigger and set the Trigger detects property to Any Object With Tag, and the Tag name to Animal feed. So long as either the Trigger or the prefab has a Rigidbody (or Rigidbody2D component if 2D), it should then react only to the spawned objects.
To be able to then make use of the object in your Trigger ActionList, you'll need to make use of a GameObject parameter. Check Set collider as parameter?, and the Trigger will then have a GameObject parameter that you can use to override certain Action fields (e.g. which object to face in the "Character: Turn to face" Action). When the Trigger detects a prefab, it'll set that parameter value to the instance, so that any Actions that use it will react to it.
Parameters are a slightly advanced topic, but they're much like function parameters if you're familiar with coding. A tutorial on their usage can be found here.
Thank you very much!
So far looks like it work perfectly.