Hi there! I'm new to Core, and i'm come from Roblox. So, i decided to write in end of get object function :Clone(), But it give me error "attempt to call a nil value (method 'Clone')". I want to know how called clone function here.
if it need, here my string with this error
local cactusClone = World.FindObjectByName("TemplateCactus"):Clone()
You can create objects from script using World.SpawnAsset (you might also want to check out SpawnSharedAsset later).
To spawn an asset you need to get a template reference, you can do this in several ways, but if you want to get it from an existing core object, then use the coreobject property sourceTemplateId (CoreObject Properties).
Yes, Thank you! But i think i guessed that i need to use World.SpawnAsset before you answered my question.
Hello again! When i make World.SpawnAsset with my object MUID i get 2 errors.
Here those errors.
Failed to find a asset manifest when trying to spawn asset object, for ID [954B06427C49341E]
Error running Lua task: [167C7E08E091DF95] Main:21: World.SpawnAsset() failed to spawn asset with ID 954B06427C49341E. Please see event log for more details.
And here my code to you understood how my code working.
local currentCactusesCount = 0
function moveCactus(cactusCloneObject)
local cactusCloneGetTransform = cactusCloneObject:GetTransform()
local cactusPosition = cactusCloneGetTransform:GetPosition()
local randomCactusSpeed = math.random(1, 3)
while position.Y ~= 4330.895 do
cactusPosition = cactusPosition + Vector3.New(0, randomCactusSpeed, 0)
cactusCloneGetTransform:SetPosition(cactusPosition)
cactusCloneObject:SetTransform(cactusCloneGetTransform)
end
cactusCloneObject:Destroy()
currentCactusesCount = currentCactusesCount - 1
end
while true do
Task.Wait(math.random(1, 3))
-- local cactus = World.FindObjectByName("TemplateCactus")
local cactusClone = World.SpawnAsset('954B06427C49341E:TemplateCactus')
currentCactusesCount = currentCactusesCount + 1
cactusClone.Name = "Cactus".. currentCactusesCount
cactusClone.Visibility = "Force On"
end
I know that, this MUID is valid, because i copyed MUID from this object.
Did you copy the MUID from an instance of the object that you had created in your scene or from the template of the object? They are not the same. Hence why I was saying to use the sourceTemplateId property of the object (and check that it has a valid one - if it is not templated, you cannot spawn it in.
Example:
You create a group called BigBob out of some cube primitives.
You right click on BigBob and select New Template From Object. You now have a template (Project Content - My Templates) that you can add to your scene. Each BigBob that you add to your scene will have a unique MUID, but they will all have the same sourceTemplateId.
If you look in Project Content - My Templates and find the template for BigBob, you can right click on that and copy MUID to use in your script. The objects in Project Content - My Templates are Assets, the objects in your scene are unique instances of those assets.
Yes, i copy the MUID from an instance of the object that i had created in my scene.
OK, so you need to get the MUID from the template to spawn it as a new object.
I save my object as template
Even if i copy Template Object's MUID it says 2 errors again...
But on this time, errors don't says Template Object's MUID's, it says MUID's that don't exist on this object
Can you say, Templates only working correctly when you publish the game or not?