#๐ปโcode-beginner
1 messages ยท Page 437 of 1
so use kinematic.
immobilize gravity is a weird term
if its not a JObject
he just forgot a comma
immobilize the player, gravity included
idk immobilize gravity I assumed they just wanted to "pause gravity"
set rb.isKinematic = true
can't you just use JToken? if not, you technically would need to handle each subtype of JToken separately
i tried jtoken as well
it also failed
sadly
yeah now that i re-read it it makes sense
wait let me show proof
I mean, if it fails, it fails in a different way
save rb.velocity to a variable and set the rb's velocity to 0. When you want to continue moving, set the rb.iskinematic true and then use rb.addforce(cached velocity, forcemode.velocitychange)
maybe
๐
Are you trying to parse a json?
yep
Why are you manually dealing with jobjects and all that?
i am trying make a text highlighter
like the keys look orange
and the strings look green
As in you're making a json editor?
the int looks blue
yep
i made everything work
aside from the JArray
dont know how to parse them
whatever you do for "everything else" do it for each element of the JArray recursively
Is this just an academic project?
just a fun stuff
i am still 18
no university yet
alright, is there some reason you want to edit a json in this way?
It's kind of going about things completely backwards
not edit
but just showcase
๐ฅฒ
What I mean to say is, why are you showing a user the json at all, instead of the actual object it describes?
JSON is a storage format. It's convenient because it's plain text, but it's not particularly user friendly
It also tends to sprawl quite a bit, especially with collections, and can get borderline incomprehensible if it needs to support references
yea same troubles here
even if i want to show the objects
I still need to parse the JArray
i dont know how to do that
did this not work btw
#๐ปโcode-beginner message
it also works
Why? You can simply deserialize your json to the object and work on your collections there
not using a specific serialized class here
just random json files
Then you're basically just building a json viewer, which is totally valid but a tad pointless. In that case I would honestly say just go look up the regex you need, I'm sure it's floating around
i also tried to resort to regex
and you had 2 problems ๐
but it was too complicated to use
so i tried this method
How is this possible? why is a non-prefab enemy able to accept the players transform but the prefab version of the same enemy calling it a type mismatch? It's the same exact script???
๐คฃ
I didn't even know there was a type mismatch message 
"the plural of regex is regrets"
More seriously, parsing abstract JSON and going through all of its elements is easily doable with type checks, and a recursive method
The root of a JSON file will always be an object { } or an array [ ]. Go through all of its elements. If one of the elements is itself an array or object, call the method recursively on the child element
in my case its an array
not like the root
but i cant parse an array
void ParseArray(JArray array)
{
// however you list the elements are here...
foreach (var element in something)
{
if (element is JArray arr)
ParseArray(arr);
// implementation for other data types go here...
}
}
Do one for a JObject where it lists the properties recursively and you're done
what does a JArray contains normally
isnt it JObject {}
The docs will tell you what's available to get on that type
There most likely is the inner elements collection yes
its kind of like not stated cuz i got type as JValue which was an integer
how can an array contain and integer directly without any JObject
[ 42 ] <- like this
JArray contains JObject which is really an int
That's why you need to type-check
ohhhhhhh
and i got 3 objects type from JObject type as well
when i ran a loop
like 92 int and 3 objects
it really goes over my head like how does it work?
You should post the original JSON payload, but an int and 3 objects would correspond to something like
[
42,
{ /* ... */ },
{ /* ... */ }
]
my json looks something like this
"Cages": {
"Array": [
{
"Dogs": 2,
"Cats": 4
},
{
"Dogs": 6,
"Cats": 1
}
]
}
}```
just a simplified one
Yeah, so first things first, the root element is not an array, it's an object. With one property, "Cages", which is itself an object, which contains an "Array" property, which is an array that contains two objects
So yes you definitely need a recursive algorithm to scan all of that
isnt the cages key in the JObject?
and the rest of the JArray is the value of that key?
In the root one. There are 4 JObjects in this JSON string
ok so keys are like objects
No, { } is an object
ohhhh
now it makes sense
the array contains 2 objects inside which there are simple keyvaluepair<string, object?>
you need something like
Parse(Jtoken jt) {
// handle boring cases
if (jt is JArray jarr) {
// foreach subelement call Parse(array[i])
}
if (js is JObject jobj) {
// go over each key value pair and call Parse(value)
}
}
I've got this script that loads a new scene when a button is pressed
// That scene will be loaded when prompted to
[SerializeField] Object scene;
public void LoadScene()
{
SceneManager.LoadScene(scene.name);
}
}```
It WAS working in the build but now it's not loading the scene at all. It DOES load the scene while in the editor. Does anyone have any idea why making the build could stop the scene from changing?
yea i got it
let me try if it works
why is it wrong
Scenes are annoying, I doubt this has ever worked with that code in build... If it's an addressable scene, I think there's a build-in something that you can drag a scene to and it works, but if it's a standard scene in the list of scenes... you'll need some custom script that allows you to drag a scene and stores the name/index/something to load it
What does it say?
yoooo
it worked
It's been working fine ever since I made it
thanks for the help your the best
all of a sudden it just doesn't
Those comments look suspiciously AI like. But if you want to drag in the scene as an asset, just use SceneAsset wrapped in #if unity editor
In the editor - sure. In builds - I find it unlikely, because it's always been a problem... unless it's been resolved in newer Unity versions
I made those comments ๐
how does it not? what's the error?
huh... Is that the same message when you hover over the red squigglies in your IDE?
Oops forgot to say the 2nd half of this,
Then in onvalidate write that scene asset name to a string
there is no error that I'm aware of
I doubt what you're doing would work considering SceneAsset is unity editor only. So dont think you can just use object to get around that
I've made a few builds and never had an issue
I must have done something then
something dumb
but what?
Are you using version control? could just see what changed directly
Or start debugging in your build
doesnt have access because the security level sth like that
I did a debug countdown before it tries to load the scene and that works fine
it's just that single line that isn't running
could be that since I'm not on VC
you made a custom SceneManager class
what :(
right click on SceneManager and do View Definition
does it take you to the Unity Scene Manager
Did you make a class named SceneManager
I don't know what a debug countdown is. I meant debug specifically like the name. Because that's all you're passing into the method anyways.
Also you should be using version control but it's not like this is related to your issue suddenly happening
let me rephrase
I'm doing a countdown as a way to debug
this?
like this
idk
yup. Do you see this is wrong?
nope :(
You should not name class name something already taken by unity
the Compiler has no clue which one you want to use unles you specify its Namespace
eg
UnityEngine.SceneManagement.SceneManager
well, dont. use actual debugging techniques and print out the name. All i see is a timer thats completely unrelated to the issue
Why doesn't it complain about the ambiguity, in this case? Does it just default to the current namespace, and only whine if you import multiple namespaces with conflicting definitions?
Don't make classes with the same name as Unity classes
iirc it looks for the one already in the current namespace this class is in
It's ambiguous if both are in imported namespaces. If there's something in this namespace, it'll be automatically chosen when there's multiples
much better explanation lol ^
If they're both external, they're the same "priority" and it throws the ambiguous reference exception
Oh alright - I suppose that makes some sense. But good to know in any scenario. Thanks ๐
the timer was to see if the script was running at all
which it is
so I narrowed down the problem to the scene loading specificially
you could narrow down the problem even further if you just debug the name like i suggested
I'm doing that next
and debugging the name, in the same method as youve shown above would also told you the code is running
hey, well, all roads and what not
#1265474997183320204 message am i doing it right?
#1265474997183320204 message it start here from the conversation
so you're doing a saving system or what?
well i am havinga problem with something, and now it comes to this whole saving thing
TLDR ideally you should explain in a few words.
What is happening vs what you expect
yea honestly i cant even find what the issue is myself and i dont really wanna read through a whole thread (even from that link) to try understanding from just messages between you and someone else
what's tldr?
well i am having problem with the muon count firt, but then we jump over to this whole saving system... but i just wanna fix the muon text changing first that like when you rescue a muon from a scene one time, it would trigger that a number chanes up on the ui text in the other scene
Too long didn't read
They are asking for a synopsis or summary to shorten the necessary reading
https://gdl.space/hanutixoya.cs and i changed "0" on _allMons to "15" so i can finally show how many muons there are instead of counting how many muons there are from different scenes...
Why aren't you just adding a script to the Muons that has void OnEnable() => allMuons++; and void OnDisable() => allMuons--;
https://gdl.space/tajixajijo.cs the muons already have hteir own script
No one knows what "muons" are. Please use more general terms instead of your game specific vocabulary.
That doesn't really address what they said at all
You could implement their idea to that script
if they have their own script just search the component directly
oh, well "muons" are like the gameobjects the player touch to rescue them from a game scene
Are you just trying to maintain a count of some kind of object?
Is that all that's necessary?
A search is pretty inefficient and would need to be repeated everytime the number changes
Or is there more to it
Then call them gameObjects/ entities or whatever.
just increment an int on creation and destruction
Im talking about caching the original list, then using events to add/remove them from said list
Nah, they would not have to repeat it. Only once on scene start. They decrement in OnCollisionEnter
public List<MuonScript> muons
mouns = FindObjectsOfType<MuonScript>();
"rescue them from a scene" is also your game specific thing. We don't know what "rescuing" implies? Is it just removing them from the scene? Or is there something more to it?
So long as all are created in awake and no new ones are added yeah, but that's a pretty rigid solution
when the player touches the muon gameobject, it does the rescue animation and then the happy animation and then disappear, like triggering them
simply adding/removing to a collection adn using the built in .Count is probably the most flexible
and even if the muons would have that, allMuons would have ared underline because allMuons text only apply in the MuonCounter
Okay, and you need a count of how many are in the current scene?
no one is saying otherwise..
Describe your issue in a way that everyone can understand without playing your game and you'll see more people try to help you happily.
How can I controll that if I click on one slot, the background highlights but the other slots background stays normal?
Do I have to have a reference to ALL the slots?
other slots? which slots
are you assuming we know what your specific setup is :?
Give each slot a function that detects when it's clicked on. When that runs, change the background
here are the ui text and the entities, they are in the level select scene while all the entities are in other different scenes where you play is, when you touch an entity (like on trigger) that would change the number up on the ui text in the level select
and what about when it is not clicked anymore?
This is a rigidly designed level. They are all placed by hand before runtime
But yeah, no one is saying your idea was bad or wrong...
Usually it's easiest to just have the collection since you'll want to update them at some point anyway most likely, but if you really don't want that then you can have each slot register a listener to a static event that passes the currently selected slot Then each slot would compare itself to the currently selected and set its visual accordingly
Okay, so, you have a UI element that shows how many of these things are in the scene, and how many you've collected?
yeah, and it is currently on "0"
What do you mean by "not clicked on any more", like when you release the mouse button?
what collection?
A collection of all possible slots
Are all of these objects in the scene at the start? Or are they spawned in at runtime?
You can either have a central controller that has references to all slots and updates them on changing the selected slot, or use an event and have each slot register itself to that for an update, same end result just a slightly different flow
no, I mean more like when I click a slot, it highlights but when I press another, the one that was highlighted turns normal and the new one highlights
they are not in the scene, the entities are in different scenes, not in the level select scene
So, you're going to want a sort of manager object, which keeps a reference to the currently selected one. Whenever you click on any of them, tell the Manager object. It will deselect the currently selected one (if it exists) and then select the new one
Okay, so it is better to have a manager then
Okay, so, in this level select scene, where do you get the information about how many objects there are?
And how many are left?
i choose the number 15 there because that's how much are the amount together from the different scenes, since each scenes have 3 entities, and when you touch one, it would trigger a number going up in the ui text in the level select scene
And what if I want the slot to be clicked to display a piece of information when it is clicked, should I use a manager or a complementary component to my slot prefab?
dont use magic numbers..
what?
https://en.wikipedia.org/wiki/Magic_number_(programming)
A unique value with unexplained meaning or multiple occurrences which could (preferably) be replaced with a named constant
In computer programming, a magic number is any of the following:
A unique value with unexplained meaning or multiple occurrences which could (preferably) be replaced with a named constant
A constant numerical or text value used to identify a file format or protocol (for files, see List of file signatures)
A distinctive unique value that is unli...
But if there aren't any instances of the object in the scene, how are you going to "touch" one to increase the count?
Each slot can have its own function that runs when its selected. The manager just calls that function
Think about it this way, let's say you're trying to show an inventory with individual slots that can each have something in it. You're going to have an Inventory object that contains Slot objects and each Slot object may or may not contain an IItem
you can't touch the objects in the level select scene because they aren't there while the ui text are there, but you can touch the obejcts when you select a stage and play there while playing as a character to touch an object so that would trigger a number up in the ui text in the level select scene
Okay, and how are you passing data between scenes?
I don't know, that is what I'm asking for on how I can do that so the number can be increased between the scenes
In those classes you'll stick all your backend logic concerning how your inventory system works. Then, you'll create your UI hierarchy and create a Manager monobehavior that contains the prefab + necessary references and positioning information and a slot monobehavior that contains all logic needed to display a single slot
So remember how we discussed DontDestroyOnLoad months ago multiple times?
Do you have any sort of save data system? Does it need to actually be saved between sessions, or just between scenes in the same game session?
yes, but the number counting it is not an object
Yes it can be
It is ON an object of course
Your UIManager should then take as input your InventoryManager and create a UISlot object for each slot in that manager, and then pass that UISlot a slot which it will render
so I should keep the display logic in my inventiry object
even if i did, it wouldn't work because root objects
No the exact opposite
Yes it could
Separate UI and game logic entirely
Nothing about an inventory is realtime, it should go in a regular C# class that doesn't inherit monobehavior
Oh, I think I didnt mention
only the UI controllers need to be monos
It sounds like what you want is a DDOL Singleton that has something like "TotalMuonsPerLevel" and "CurrentMuonsPerLevel" as dictionaries. In your UI scene, you read from that singleton to get the values for each level.
If you need to save the data, you can just serialize that object to disk using JSONUtility, and reload it when you start the game
My architecture is all about having an ABSTRACT InventoryManager which is a list that stores objects, A CentralInventoryUI in which I separate my objects into slots of prefixed capacity. Then that distribution is passed to all of the different inventory UIs (The main one, the one in the crafting station...)
Ok that doesn't change anything though
also by definition your inventory cannot be abstract since you actually seem to plan on, you know, having an inventory
abstract in terms of that this list isnt shown on screen but obviously exists, the screen representation is carried out by the different Inventory Uis
the DDOL gameobject needs to the Root like it says
Yeah, you need to make changes of course 
That doesn't mean it won't work....
Put the object counting the muons on a root object
that's not abstract, that's just C#
abstract has a very specific meaning
yeah sorry
You're actually talking about what I was saying before
So put it on a root object
99% of your code should NOT be in a monobehavior
Why is it on a child object in the first place?
so yes, your inventory should be a regular boring object and it will have a collection of items, then you'll pass your inventory to a InventoryUIController mono etc
the script is on a ui text that is in canvas
Eh, that's a bit high. I'd say an average Unity project will have about half their code in non-mono. Monobehaviours are pretty powerful, you gain a lot by using them. I don't think they should be avoided
Then put it somewhere else
It depends massively on genre of course
In something like an FPS or a physics game probably the majority of code is going to be in monos
then its not Root. Root means its the top parent object
The closer you get to a spreadsheet/strategy game the more you want to just use Unity for UI and little else
Also, anecdotally, the fewer monos you have the less of a pita save/loads become down the line
so i have my turrets working but the bullets are weird like they arent rotating with the tip of the bullet towards the enemy or and they are in the same position , im a bit confused
where do you set the rotation
Quaternion.identity means no rotation
you need to show us the SetTarget function
Here's the thing you seem to be forgetting.... you can move it.....
im kinda not setting the rotation
you probably want your bullet to inherit the rotation fo the gun
then that explains why its not rotating
so your question is self answered lol
think about it this way, the bullet should be going forward out of the barrel of the gun, which is hopefully also pointing forward
pass the firePoint.rotation on instantiate
i haven't forgotten, but even if i remove the ui text away from the canvas, the ui text would jsut disappear from there
The ui text and the manager counting muons can be on..... different objects
So no, you do not need to move the ui text
never heard of JSONUtility before
Don't remove the UI text
Why are you assuming the text needs to be the Singleton
Hey does anyone know how to adjust the rotation offset of the rotation constraint GameObject Component? I've been searching the internet for like an hour and I can't find any documentation on this.
If you're setting rotation by script anyway, why not just clamp?
this?
Let me try that
did you see there is settings
yes im aware, im trying to dynamically adjust the offset
do you mean with code?
at that point why even use the rotation Constraint if you can just do it via .rotation
anyway @cold belfry if your IDE is setup right you should be able to just start typing the name and have it pop up
it works now
ie
yeah that's strange i don't know why it didn't autofill for me
when in doubt always look at the manual
https://docs.unity3d.com/ScriptReference/Animations.RotationConstraint.html
make sure your !ide is configured
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
โข VS Code
โข JetBrains Rider
โข Other/None
either way thanks a lot yall ๐
make sure your ide is configured ๐
i will
and you probably already know this, but you can almost always get all the available methods and their params & overloads by just typing '.'
*if your ide is configured
i am working on trying to make that the script can have hte uitext attached to it
backticks not single quote
its above tilde key
I'm well aware of how to do code blocks
ok, now i have done that
colorful
is that why you wrote it with single quote instead of the code formating
yes
it's a period, not code lol
well . makes more sense, they might confuse the ' to be used
technically an Operator not a period

didnt we go over saving last time?
i meant putting the script on a root object while attaching the ui text to it
also..
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators
operator
It's a built in utility for parsing JSON files
These operators include the dot operator
sorry don't mean to bother you again but i checked and my IDE is set up, yet i don't have the ability to see available params and overloads
It's called the dot operator
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators
Did you google it. When you haven't heard of something, take the time to research it on your own
hmm can you screenshot your IDE really quick
sure
which IDE?
im using vscode
make sure you get rid of the older Visual Studio Code Editor package too
yes i followed all the steps
ah okk i will try that
regen project files after with vscode closed.
open script again in unity
The package. In unity
Just to be clear
alright hold on ill try regening project files
https://gdl.space/exenomivus.cs i do have this
Well stop trying to do that.
The UI text and the thing that keeps track of the numbers should be different objects
i just did
just realized 2023/6 didnt even include the Visual Studio Code editor package anymore.. nice.
#๐ปโcode-beginner message i just did here
Okay, now you can have your dictionaries like I suggested earlier and have the UI read from it.
like this?
this local dictionary is gonna do what exactly?
I don't know... i just searched up what dictionary is
and what is it?
by now you know the differences between local variables and member fields right?
yeah
okay because you can only use that dictionary in awake right so idk what ur intentions is
So then you understand why declaring it in Awake is wrong?
So I regened my project files and tried what you said here, this is what i ended up with
im on unity 2022
well I said to remove it, you did not
You have to remove that package as said
i can't remove it though
Remove the Engineering package first
its locked to Engineering thats why
ah ok
If you encounter a new concept in programming, do a proper research and read the docs instead of copying the first code that you find.
is it like for example public string object { get; set; }?
no thats a property.. completely unrelated to dictionary or declaring one
Use a thread, since your issues take days to fix.
there, a thread
So now that you know what one is, you can implement this
#๐ปโcode-beginner message
like this?
alright i removed my visual studio code editor package as well as engineering, i now have solely visual studio editor package installed, additionally i regened my project files. I am still unable to see available params etc
show the output window from VSCode
check for any errors for .NET SDK
the output is somewhat large should i post it in here?
does it say anything about .net sdk missing?
or dotnet command not found
let me see
something akin to this yes
2024-07-24 16:43:55.286 [warning] Via 'product.json#extensionEnabledApiProposals' extension 'ms-dotnettools.dotnet-interactive-vscode' wants API proposal 'languageConfigurationAutoClosingPairs' but that proposal DOES NOT EXIST. Likely, the proposal has been finalized (check 'vscode.d.ts') or was abandoned.
this is a warning this might not be it. anything else?
send the log here https://gdl.space
Wait im incredibly stupid, it's working now, sorry for the confusion
Thank you for your help though you are genuinely a goat
What? No....
what is the point of the singleton here and the Instance= this. Will this ensure that there is just one instance of AIManager?
i am currently talking in the thread right now
no it just assigns the current instance from this instance, to that static field
also you dont want to have a public set
you should however deal with also a edge case where theremight be two AIManager scripts in one scene
good example here ^
right here
what would be a possible use case of assigning current instance to a static field?
easy access to the current instance
AIManager.Instance.Spawn() for example
the difference here is that you dont make everything like methods and field in the class static. Doing that would cause other issues, in unity specifically you wouldnt be able to assign any static field through inspector
I need to run some functions to initialize some data before the game starts because many scripts will rely on this data being initialized. How can I do this without worrying about keeping references to each script that requires such data?
depends what it is, one way is store it in a scriptable object and just have that inside whatever class you need
*some whisper from the distance*: Just don't do DDOL singletons, they'll make you really sad!
I mean..Singleton is valid too but I think they said they want to avoid reference ? idk
i am still having problem with the script
If i want to display the information of a slot should I have a Display component on the Slot that passes to a Manager that displays it?
should it be an EventTrigger?
Are scriptable objects singletons? As in, they run just one and only one instance of them exists?
meaning the instance stays the same across
closer to a static variable
if you change 1 scriptable object value it changes for all of the ones that have that SO
so its the same instance yea
well we would need to see some code
we cant really help you without seeing anything ๐
well use this !code format and you will be fine
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
You can just state your issue there are more people here lol its not a turn based help channel
I read it and still dont understand the issue
lets start with that one
can you give me a quick , whats supposed to happen vs what is happening instead
the item is supposed to be filling an item paremeter in the inspector
its not
thats what i saw
through code?
yup
we would need to see the specific code that is supposed to do so
send relevant scripts lol
if you have so many scripts to handle a specific thing you might have a design issue to begin with..
is it throwing an error ? start with the stacktrace
ok so first one to start is InventoryUIManager
UnityEngine.Debug:LogWarning is a custom message though ? did you write this script or get it from somewhere ?
I would avoid "AI" as you're learning because it can mislead you and also not teach well what you're writing
anyway send the script via link something like https://gdl.space
where is DropItem called
InventorySlotButton ?
send that
im looking more towards slot.SetItem(item, itemPrefab);, they said the item slot is not filled up so they cant really drop nothing
well i guess i just found the script i was looking for
where is SetItem called
SetItem is probably passing a null somehow
In my InventorySlot script (I think)
give it, please
oh right I see
so you have a InitializeInventorySlots with null
wait where do you see that
which script
InventoryUIManager
are you destroying the item gameobject ?
this might be a reference issue where you're destroying the item
im talking about the item though
is that ClickableItem
what is item
yes but gameobject wise, is it something you do destroy or something
when do you destroy it ?
no Im just asking if you're destoying the gameobject before Drop
cause I see it says missing in your screenshot
I can't read on white background sorry
also screenshots ๐ตโ๐ซ
I understand the intention but its important to know if you are destroying it somehow before hitting DropItem because you wouldnt be able to drop a null (destroyed) object
transform.Find("Border")?
also don't use?. on unity components
doesnt work
look at the inspector since the field is public
before you hit drop item, check if the item is in the field of inspector
visually looking at it
start narrowing down issues
so when you pick up item it says Missing ?
under Item ?
what about the slots
InventorySlotButton slotButton = slotObj.GetComponent<InventorySlotButton>();
where is ClearItem() called, sorry i was away for a bit
no. the List
that you initialize
screenshot that during playmode when you said it shows "missing"
yes
want to see if you already missing all of the newItems there
make sure to uncollapse the list elements
on InventoryUIManager the List of Slots
wait its private
nvm
put [SerializeField] private List<InventorySlotButton> slots = new List<InventorySlotButton>();
line 13, on inventoryUImanager
yes seems like the slots are initialized correct but the item is not
then passing null and causes the warning
the code is a bit confusing at first glance
yeah show the list during playmode
i know this is vague but do you know where you set item to null or delete it?
i cant think of anything else
that would cause this
the inspector
no mate. this is not a list, these are gameobject
in playmode
the List is the thing that says List in the code
oh right they are components and not a poco
ok my mistake
they will not show the nested fields

so each one of those has missing as item
or is it just 1?
does this run ?
Debug.Log($"SetItem called. New item: {item?.name}, New itemPrefab: {itemPrefab?.name}");
what does result say
an item can fill up one of those slots
that shouldnt be a problem
unless unity wanted to be a dingus today ๐
its already in your script lol
im asking what its printing
yes If i were you Id start from scratch
and not touch ai
at all
following a guide maybe but you have to understand your own code to debug it
knowing what Debug.Log($"SetItem called. New item: {item?.name}, New itemPrefab: {itemPrefab?.name}"); prints
should shine some light on what it is exactly being SetItem with
(missing) usually implies the gameobject was destroyed
wdym by "Destroy" messages
is that one the one that works?
or the one "missing"
you can put this
void OnDestroy(){
Debug.Log($"{name} was destroyed", this);
}```
inside `Item` script
but its printing the correct name right
because you're grabbing that from item
{item?.name},
it would throw null otherwise
having to fill manually is not "function correctly" lol
you're covering up the main issue which is why item goes missing
well yes because its passing the null check..
if (slot.item != null) // Ensure there's an item to drop
You put this warning here
Debug.LogWarning("No item to drop.");
if its not found
so finding out why is going null
check if it printed anywhere
sorry for interrupting your conversation, but can someone help me with this problem? I don't see how the game object is both active and inactive
what about the parent object?
well there you go..thats why its missing
hm i'll check rq
the power of debugging โ๏ธ
which script does it btw
either I'm blind or you never sent it
no i mean which scripts destroys it lol
the parent is active too
ahh so you did never sent it. Good to know I'm not going blind
remember reference types are pointing all to the same object
so if you remove it from the scene, its gone everywhere else
why destroy it if you're gonna use again to drop it or whatever, easier to just hide it. aka Inactive
Debug.Logs or logs in general can be very useful if know how to use them ๐
yes tbh should've been your first thing you learned in unity lol
debugger is next , you will be on some 5D galaxy brain
how do i check that?
is the Checkmark on ?
but it probably has a specific warning on disabled component
yeah its checked
can you show the complete console when that message prints
no crop preferably i mean
theres 2 errors but they're from an unused script
if its unused why would it error?
alr share the screenshot with all logs
no crops
including the sides
edge to edge no crop
is this object child of something
which one
the one that calls Animator
i feel like one of the parent is inactive when this is called
root
so it has no parent ?
yes
something obvious I'm not seeing lol
btw when do you call that method
its a little complicated, but first update runs in something else, then if a key is pressed the player moves and it calls the tick, then in the enemy script when it recieves that it tries to move towards the player
sounds..complicated..you mean you have custom tick movement?
yeah its turn based
oh okay. Not sure it would matter unles you're calling it on the wrong component which doesnt seem you are..
maybe step through code with debugger and see whats happening when that line is hit
https://gdl.space/ujehumiwox.cpp is there anyways to save the data from the uitext from going back to 0? when you exit the game and play agian?
Yes, using JSON or Binary files. JSONUtility was mentioned earlier, have you researched it yet?
but don't i already have the load and save code there?
where is GameData stored
Ok, I see you went with PlayerPrefs.
Where do you call LoadData?
Honestly, if you just go back through those MASSIVE threads, you've been told everything you need. You just need to take more time reading them and actually thinking about it
You are trying to go too fast which makes you ignore things
https://gdl.space/lebefeluvu.cs this one
this aint even it
go back n read the threads, because the load and save is the same across..
just apply it to different data..
Do you see LoadData() in that?
Edit: i guess I should be clear. Not where you DECLARE LoadData, but where you call it
no
Ah, too slow with my edit....
Where do you CALL LoadData
You know by now that if a method is not called, it will not run
Yo
so guys, I watched a toutorial where they typed Rigidbody, and Mathf into a script editor from unity and it turned green, does anyone know what extensions and scripe editor is best to do this?
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
โข VS Code
โข JetBrains Rider
โข Other/None
Visual studio better tho
Honestly, misread your message. Visual Studio, Visual Studio Code, and Rider are your choices.
All are fine. You cannot use Visual Studio on mac though. Also, Rider costs money, but is the best
oh well... i don't have loadData that calls somewhere in the script
Ok, then you will not load data of course
And I said call LoadData, not LoadData calling somewhere
So in here is all beginners
What?
Are you asking if everyone in this channel is a beginner? Or if the channel is only for helping beginners? Or what?
- no
- yes
- not sure
am i supposed to call loaddata from the counter script? in another script?
Yes helping beginners
Call it from wherever you gave the GameData instance
Yes it is. In coding specifically
Ohhh
this is my first time seeing a void function like this. How would i go about calling it? Tried alot of stuff but always get a null exception error. public void NextSentence(out bool lastSentence)
Yea I need to learn coding
Think of out as a second return
call it the same way its wirrten
NextSentence(out bool lastSentence)
NextSentence(out bool lastSentence)
Can anyone train me
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Dang
gave the GameData instance? oh wait you meant the GameData script?
No
Not the script. The instance of the class in memory
by now you should know what at instance is..
If I press help and go to unity API refrence I can see the commands I am looking for, but they do not come up under suggested when I try to type it
I know what it is
so why do you ask such questions?
Then it is not configured
NextSentence(out i) this didnt work so...
Which ide are you using
the instance is the one that is created new() somewhere. So your question makes no sense. you should know where you put it
Missing bool
Unless you have a bool variable called i within that scope?
yes it is
im using visual studio
Show the code
define "didn't work"
And you followed EVERY step in that guide?
public void SetAutoButtons()
{
Status.instance.yes.onClick.RemoveAllListeners();
Status.instance.no.onClick.RemoveAllListeners();
Status.instance.yes.onClick.AddListener(() => CompleteTask());
Status.instance.yes.onClick.AddListener(() => dialogueManager.NextSentence(out i));
Status.instance.no.onClick.AddListener(() => dialogueManager.NextSentence(out i));
}```
just throws a null exception;
which line
Well that is because dialogueManager i null
Not because of the method call
Most likely at least
let me double check that
Show the exact error, word for word, including the stack trace.
Edit: if you don't get it yourself
bloody hell. Thanks. Im so dumb
i have wrote inthe instance in the counter script
To be clear, you don't mean a static variable CALLED instance, right?
You mean the instance of GameData?
this tells me you don't know what instance is.
Just looked, you did mean a static variable called Instance....
That is NOT what instance means, which leads me to believe you do not know what an instance is
Also, you do not even set Instance in that script, so it is null 
it is not so easy to remember everything since all i do is forget and forget, that is what I always do...๐ข
I read it all, and I think I did it all. but it was a little confusing
Ok, show your External Tools menu
in 3d for making a player move i have the getaxis for horizontal for left and right arrow but what do i put to make the player move on the z axis..?
if you forget then you need to practice it more before you move on the next thing..
GetAxis vertical
ya im there, do I have to do something there?
Show it with a screenshot
like its been literal months and we guided you through a bunch of it. Seems you just want to move on to the next thing while not fully absorbing what you learned, this way you can't problem solve on your own..
Every time you learn a term, write it down
Next to it, write down the definition and an example. Every so often, cover the definition and example and try to say out loud what the term is. Test yourself.
so I have this procedurally generating texture, but when i save the scene it vanishes into dark. is there a solution for this? or will it just not matter since the scene probably wont be saving during gameplay
No, the external tools from the guide
the solution is not even loaded
It is in unity
Instance = refers to an object's relationship to its class?
huh?
An instance is a specific object in memory
@hushed hinge no, instance the object created from the Blueprint. Aka a class/struct
Unity instance also can refere to GameObject/Component
What do you mean huh? If you look at the guide, it tells you where External Tools is. It is not in Visual Studio, it is in Unity
The one you screenshot is different
creteated?
ohhh, im stupid, the unity one
Obviously a typo. Guess what they meant
oh
well... i don't know what i'm suppsoed to write in the loadgame or savegame to save the uptatedtext from MuonCounter script...
you're passing GameData from somewhere, decide where to store it
You call LoadData and pass in the GameData instance (which is in a dictionary if I remember right)
but savedata and loaddata only save the amount of coin counts, it doesn't have anything with updatedtext
Ok nice.
Close visual studio, then Click regenerate project files right there
what are you trying to save with the text?
One step at a time. That is completely irrelevant right now.
Once you actually LOAD the data, and fix the Instance variable in the counter script, it is trivial to set the ui
ok
it still doesnt work
That was fast...
did you close vs and open script again?
yep
open the solution explorer in Visual Studio
top left
Where are you opening it from? Inside unity?
yea
the score?
fix the instance variable in the counter script? but i don't know which needs to be fixed
not score, from the entitties you have touched
so you know how to save score? its the same exact process..
@elder kite Ok, did you install the workload in Visual Studio? It would be this part
I told you earlier. You do not set it, so it is null
Simple as writing Instance = this in awake
yet it wouldn't work with muonCounter.UpdateText();
yet red underline on INstance since there is no word of the Instance somewhere else
if it didnt work then you didn't do the same
It looks like there is to me
https://gdl.space/lebefeluvu.cs
that was the muoncounter, i was talking about counter script
i thought you meant that
@hushed hinge I'm not going to keep pointing you to use a thread.
I was talking about MuonCounter.
Since it... you know... HAS A VARIABLE CALLED INSTANCE
lol ๐ธ
how do i find cinemachine from this?
You're only viewing packages you have installed in your project. Open the drop down to see them all.
ah yes thx
@fathom bramble chan you show !code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
or atleast error message
Is this easier to see?
or do you prefer the text
but basically I get a null reference with ui.TriggerGameOver()
The the ui is not assigned at that point.
i forgot abt that..
that's what I'm asking, how do I assign it? Unity screams at me if I use new
You probably want the serialized reference method in the link I sent before.
Just drag and drop it
I need some help with UGS Cloud Save.
I'm saving my Character to cloud save, you can just directly save the class, no need to serialize it or anything.
How do I prevent game crashes when the data structure changes?
How can I check if the data structure is still intact without crashing the game?
How do I prevent overwriting an existing Character that fails to load?
It gives you and error. Not screams at you. No need for the drama
Just read the link I sent before. It tells you everything you need to know here
https://unity.huh.how/references
If UIManager does not exist yet, then use Instantiate as I said twice already
I recommend going through the unity !learn beginner courses as they cover that and many more things.
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
You haven't shown the code that throws the error
The error is line 37 there
#๐ปโcode-beginner message
the easiest way is to add a reference to it that you set through the inspector
if you don't know how to do that, you really need to watch the basics of unity, you pretty much use it for everything
you can also use the Instantiate method, which you use to create new MonoBehaviours instead of new
but I doubt that is what you need here
I've already tried that, it won't give me the option of selecting the UIManager script from the inspector
and manually dropping it is not an option either
No, it has to be an object
Not the script itself
A script is a blueprint, it does not "exist"
You need an instance of the class, which is a component on an object
So create an empty gameobject, attach the UIManager, then drag that object into the box
MonoBehaviour inherits from Behaviour, which inherits from Component
That is important to keep in mind. All MonoBehaviours are going to need to be a component of a gameobject to be useful
Does not work, if it says type mismatch
if this helps
is your script on the UIManager gameobject?
Yep
show it pls
Nah that's just Unity that adds spaces
any errors in console?
ah lol
you're trying to add an object from the hierarchy to a prefab, that's not possible
Prefabs cannot reference scene objects
Prefabs are like blueprints (I know I used that that analogy already). Your blueprint cannot mention "the house two doors down", because it may be built in a different city
You will need to instantiate, store that reference the method returns, and the inject the reference where needed
This is a staple in pure c# where you will use di a lot more in Main
Enemy newEnemy = Instantiate(prefab)
newEnemy.Initialize(UiManager)
You could also just make UIManager a singleton.
UIManager.Instance
This is all mentioned in the link i sent twice before
DI is standard in pure c#
It is the c# way to do it, not the unity way
The small inconsequential difference being that you would generally do it in a constructor
But calling that different would be wild
It's a bit complex to understand at first, takes a while to get used to, but once you understand, it makes a lot of sense
I got very confused with references on prefabs at some point too
hello everyone I am new to unity and was planning on making a game with a friend so we joined the UCVS and i was messing with the branches and made /main/test/ and /main/test/m and wanted to move /m back into the /main/test and then back into /main, when moving i was told i could only ove into empy branches and when trying the merge it made that weird loop and was wanintng to know if there was a may to move or merge it wihtout the weird loop. I accidentally separated the setting from the root and was wanting to put them back while also learning this for future refence. I am new to the git stuff.
Then it's definitely not how I've ever done it in any game. My general way is UIManager.GameOver()
just one line
done
if you make UIManager static or a singleton you can still do that
Well yeah, that would be a better way, but you are insisting on calling it from Enemy
If you wanted to call it from inside an object in C#, you would have to do it similar to how I showed above of course. You could not just call UIManager.GameOver without injecting the reference to UIManager
But as I said multiple times.... singletons are explained in the link I sent
The thing that may be causing confusion is that in c#, you have access to Main()
You set up all the references there. You pass everything in as needed or are just IN the same scope as the references you created. But in Unity (and Bevy, Godot, Unreal, and every big game engine I know of), you do NOT have access to Main. The engine consumes it, and calls things for you.
You have to understand that fundamental fact to proceed.
Christ I finally fixed it. I appreciate all the help @summer stump @topaz mortar. All I ended up doing was ripping out a pub-sub system I wrote in another C# game and I put it in here
no need for references, everything communicates through a common messagebus now
yeah this looks much simpler than adding a simple reference ๐ค
but I guess you know what you're doing
Certainly one way to do it ๐คทโโ๏ธ
@summer stump @topaz mortar I seriously do still appreciate the help you provided. If you guys were curious, this is the game so far
I'll uh..have to make the brightness on those bursts less..hurt my eyes
Nice. And no problem. Good luck with it all!
cool, hope you have a epilepsy warning lol
void ShootBullet(){
if(isCoolDownAvailable == true){
GameObject bullet = PlayerBullet.instance.GetPoolObjects();
if(bullet != null){
bullet.transform.position = muzzlePoint.transform.position;
bullet.SetActive(true);
if(playerTransform.rotation.y == -180){
bullet.GetComponent<Rigidbody2D>().velocity = Vector2.right * -bulletSpeed;
}
if(playerTransform.rotation.y == 0){
bullet.GetComponent<Rigidbody2D>().velocity = Vector2.right * bulletSpeed;
}
DoMuzzleFlash();
}
StartCoroutine(StartCoolDown());
}
}```
Please help, the bullet isnt going left. angle -180 is when my player has turned left
rotation is NOT eulerAngles
why would it matter? its just using the value to check if the player is facing left or right
i used a different method, retrieving direct information from the joystick but it still has the same problem
then what should i use?
euler angles
this is the natural XYZ rotation you're used to.
transform.rotation represents a quaternion, which is a complex 4d rotation
oo
yes what you see in the inspector is Euler angles
log the if statement to see if its actually hitting
also log the velocity of the rigidbody
Debug.Log("Before Push");
bullet.GetComponent<Rigidbody2D>().velocity = Vector2.left * bulletSpeed;
Debug.Log("After push");
}``` i did this to log
Before push isnt coming
but the bullet still spawns
Debug.Log playerTransform.eulerAngles.y before the if statement
says 0 when right and 180 when left
but if i check in the editor, its says -180 when left
only whats in the code matters
you could absolute the value but usually its always 180
then why would it change in the editor?
the editor can keep going past -180 for example
works now, thanks
also
if i add a light compnent to the enemy bullet, would it be performance heavy? or just adding some post processing is better
Honestly I'd stay away from checking the angles like this, at some point in your code you set the rotation. You could at the same time, declare that its facing left or right with a bool
i just want it to feel like a laser
i tried that, but it didnt seem to work for some reason, the code was correct
๐คทโโ๏ธ if the code was correct then itd work. Not really much for me to say there
yeh you are right
can anyone help me in a unity input reblinding menu problem?
im following a tutorial and whenever this guy runs his code it opens up int the console cause its a console app but when i run my code it just opens in the terminal tab within vs cdoe
this is a Unity discord
also it makes no difference between the two, vscode integrates the terminal in the editor.
If I have a script with a function like this:
void Jump()
{
// If not grounded just quit
if(Grounded == false)
return;
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity += transform.up * jumpPower;
}
}
I need to hook up my animator to this so I want to detect for a spacebar input on another script as well, will it trigger both input scripts or is it a race?
What do you mean trigger both scripts? You pressing space doesnt run this code, the code runs (i assume from update) and checks if space was pressed. Any script checking for it will see the same value that frame
Hey how do I fix this please. I'm new to interfaces.
To my knowledge I think this says that the interface is not public but I wrote "public interface" so I have no idea.
its complaining because your implementation of fired is not public
and, of course, because you have not implemented public selected
I always find it easier, when implementing interfaces to let the ide do so using Quick Actions
Ohh okay thank you!! yeah it seemed to have fixed it but now a theres a different error
tried playing around with it but I can't find a solution
that has nothing to do with the interface. WeaponObj is null
Oh. do I set it to an object? I pretty much want the interface to be global through out all the scripts that I can use any time as a preset
that is the point of Interfaces but, of course, they do need a specific instance of an object to work on
So I have a Spellbook GO that contains spells with a Spell script on them
I made a copy of it with Instantiate(SpellbookGO), so I can show a smaller version while in combat to show the active spell
But for some reason that removed my Scriptable Object references the Spells have?
Not sure how it can even throw an error?
{
if (spell.SpellSO.Description != null && spell.SpellSO.Description != "")
{
fullItemDescription += spell.SpellSO.Description + "\n\n";
}```
195 is this line: `if (spell.SpellSO.Description != null && spell.SpellSO.Description != "")`
so somehow it doesn't copy the SpellSO field/reference dunno what to call it
This is how I copied the GameObject
{
combatSpellBook = Instantiate(spellbook, combatSpellBookTransform);
// Loop through all spells
for (int i = 0; i < combatSpellBook.transform.childCount; i++)
{
GameObject spell = combatSpellBook.transform.GetChild(i).gameObject;
spell.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.4f);
}
}```
we are missing a lot of context here like the inspector of spellbook and the contents of the Spell component on it
yeah I know, but the version I'm Instantiating from* works, so not sure what more I need to provide
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
ุ
{
combatSpellBook = Instantiate(spellbook, combatSpellBookTransform);
// Loop through all spells
for (int i = 0; i < combatSpellBook.transform.childCount; i++)
{
Spell spell = combatSpellBook.transform.GetChild(i).GetComponentInChildren<Spell>();
Debug.Log(spell);
Debug.Log(spell.name);
Debug.Log(spell.SpellSO);
Debug.Log(spell.SpellSO.Description);
}
}```
so for some reason it doesn't copy the spell.SpellSO from the original gameobject?
i`m using this to make a menu to rebind controls
and yes I am certain the original has it because I can see the description in SpellSO when I hover it ๐
and here is the inputs if you want to check it
and this
the problem that i have to set the action in here in play mode or it won`t work
i have to change the action and the blinding in play mode or the blinding won`t work
can anyone help me it`s the second day with the problem
So Instantiate doesn't seem to copy the fields in the scripts attached to the gameobject you're copying (in this case)
Any way around that?
what?
not talking about your issue ๐
Start from logging the SpellSO in the original object and then sharing the code of it's implementation
The original works, it's just a field SpellSO that contains a reference to my scriptableobject, which I'm 100% sure works, because I can see the description when hovering the original spell
The issue is, I'm copying my spelbook gameobject in my scene with combatSpellbook = Instantiate(spellbook)
And the Instantiate is not copying the values of my Spells script on my spell objects in my spellbook, it's just giving me empty Spell scripts
This. Most likely the original has null as well - no reason a copy wouldn't succeed and more likely the original isn't the target you think it is.
but I've debugged it and it showed me the Spell I'm expecting, but all the fields on it are empty
prove it. Show the relevant inspectors as I asked earlier
Oops it's actually this one:
I'll try
combatSpellBook = Instantiate(spellbook, combatSpellBookTransform);
Debug.Log(combatSpellBook.transform.GetChild(0).gameObject.GetComponentInChildren<Spell>().SpellSO.Description);```
Is that Spell->script supossed to be an SO? Becaise it isn't
no, there's a Spell script and a SpellSO reference on it
not on that image there isn't
it's not exposed to the inspector
{
private SpellSO _spellSO;
public SpellSO SpellSO { get => _spellSO; set => _spellSO = value; }```
if it's not serialized it wont be copied with instantiate
ugh
private SpellSO _spellSO;
public SpellSO SpellSO { get => _spellSO; set => _spellSO = value; }```
thank you ๐
https://gyazo.com/296858ce1dfb960765757ca48df29f7e
Can someone help im not really sure why it wont jump up sometimes
the full code is too big but lmk if you need it i can send it on pastebin but this is it
void Jump()
{
// If not grounded just quit
if(Grounded == false)
return;
// If cooldown not met, quit
if (Time.time < timer + jumpCooldownTime)
return;
if (Input.GetAxisRaw("Jump") != 0)
{
timer = Time.time;
rb.velocity += transform.up * jumpPower;
AnimationManager.instance.JumpAnimation();
}
}
It doesnt make any sense to me that the rigidbody velocity code wont trigger but the animation will??
to me it looks like the jump is a bit too early, so it's just cancelling the downward movement with the jump, just guessing though
This is the beginner coding channel. If it's not related to coding, you should try elsewhere (to move, delete here and post your original message elsewhere - looks related to #๐ฑ๏ธโinput-system or #๐ปโunity-talk and not specific to code)
Omfg you're right how in the flying duck did you get that
because you can see the jump animation starts while you're still moving downwards lol
how did you miss that? ๐
okay
Is there any way to check an objects order in its layer?
been googling it can't find a solution
I want to be able to check all game objects in range and select the one with the highest layer order
var mousePosition = Mouse.current.position.ReadValue();
_itemRectTransform.anchoredPosition = mousePosition;
My mouse position, let's say at the center of the screen. But the actual GO is... outside of the canvas. Anyone know why?
Break the problem down. If you've got an array, you'd just grab the object relative to the layer - assuming you've got some means of acquiring the objects already.
Currently it selects, I think the closest, but it looks a bit random
Log where you think the mouse is, where the center of the screen is (yes, it's an actual point in 3d space) and where the anchor position is.
but the selection is based off of the layermask
It's somewhere in ~ X -753 Y 686, but Mouse.current.position.ReadValue() gives me ~ X 1057, Y 1719
I think you need to transform the mouse position to game position somehow, not sure how it works
shouldn't be too hard to find
they're not the same thing somehow
Hey guys,
TerrainData doesn't support YAML MERGE ? It must be handled by Git LFS to avoid corrupting ?
Typically unity assets(and assets in general) are not very tolerant to merging. It's better to avoid it.
So it is better to support .asset with lfs instead of yaml-merge ?
I'm not sure how to do it with new input system
That's not what I said. I said that it's better not to merge them at all. Meaning, make sure only one person works on the asset at the same time. As for wether you store it in your repository and how is up to you. I don't think there's much of a difference.
not sure if that helps or is even relevant
but since no one else answered ๐
tried this already
the code you showed doesn't show any of that
because I tried and it didn't worked so I swapped to my original code?
it's kinda overcomplicated imo
About Terrain Data it is really an issue because with using yaml-merge it is always corrupted on git repo. I'm trying to figure out why that happens about Terrain Data tho
alright, let me try again then
What meaning are you putting into "yaml-merge"? It might be that were speaking of different things?
unityyamlmerge I mean from .gitattributes
merge=unityyamlmerge eol=lf linguist-language=yaml
Yup
Well, it's the first time I hear about that feature, so not sure I can answer that question.
Anyone ?
Anyone know why my player's gizmo thing is not at the actual position of my player?
if(Input.GetButtonDown("PickUp") && heldWeapon == null && Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 10f, LayerMask.GetMask("Item"))) {
PickUp();
}
}
private void Movement()
{
rb.AddForce(Vector3.down * 5, ForceMode.Force);
// calculate move direction
moveDirection = transform.forward * verticallInput + transform.right * horizontalInput;
if(grounded)
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
else if(!grounded)
{
rb.drag = 0f;
rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);
}
}
...
void PickUp()
{
Debug.DrawRay(cam.transform.position, cam.transform.forward*200, Color.red);
heldWeapon = hit.transform.gameObject;
heldWeapon.transform.parent = weaponHolder.transform;
heldWeapon.transform.gameObject.layer = LayerMask.NameToLayer("Weapon");
heldWeapon.GetComponent<Rigidbody>().useGravity = false;
heldWeapon.GetComponent<Rigidbody>().isKinematic = true;
heldWeapon.transform.localPosition = Vector3.zero;
heldWeapon.transform.localEulerAngles = new Vector3(0, 0, 0);
heldWeapon.GetComponent<Collider>().enabled = false;
}
- You've got it set to center, not pivot
- It's not clear which game object the cylinder is on, if it's not the selected game object, then it's position is probably not 0,0,0
I've got OnCollisionEnter running inside my script
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Breakable")
{
BreakObject(collision.gameObject);
}
}```
But if it hits anything that has the tag "Breakable" nothing happens, anyone know why? (BreakObject) prints "Broke An Object!"
It's got a convex mesh collider, I've tried with and without istrigger.
have you tried to use CompareTag rather than tag ==
Even if I'd just do console.log in the void oncollisionenter, it didn't display anything either. So I'm just switching to using a raycast
console.log ??
Yeah?
does not exist
Er sorry I meant debug.log
Even if I did debug.log it wouldn't print anything in the console
so the collision is not happening at all
Apparently
screenshot the collider that has this script
so thats a trigger not a collision, you are using the wrong method
Nothing has a rigidbody
no RigidBody, no collision event
?? You can't work off of just a collider
Do I need to make my crowbar or cube a rigidbody? Or both?
read the docs, they are VERY clear
