#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 432 of 1

eternal falconBOT
polar acorn
#

Is it a 3D Physic Material? There's a separate one for 2D, under the 2D menu rather than the Physics one

spark tulip
#

Yes, I will try that. Thanks for the response.

#

I think the problem might be related to the fact that variables are passed as copies or that the function should have a return parameter to be processed in the main class. Hmm, what's the issue?

polar acorn
# spark tulip I think the problem might be related to the fact that variables are passed as co...

Okay so it's not the input that's the problem, let's move on to the next step. Your rigidbody parameters will be passed as references, but all the floats and bools are going to be passed by value, as a copy. It doesn't look like you're actually expecting them to change though, and bubble back out to CarLogic so that shouldn't be a problem.

I wonder if CalculateTorque might be the problem? Try logging frontTireTorque and backTireTorque after you get them, see if they're what you expect

ivory breach
#

Update: I'm doing something wrong with the foreach loop to change the enemy's materials, but I don't know the cause or solution

polar acorn
ivory breach
#

This error popped up without that multiply sign

polar acorn
wintry quarry
#

use a for loop, not a foreach.

#

but also you need to copy the array, make the changes, and copy the whole array back in

#
Material[] mats = myRenderer.materials;
mats[1] = something;
myRenderer.materials = mats;```
dirty example^
rich adder
#

np. did everything work out?

radiant frigate
mint remnant
#

I seem to keep getting burned by inspector values overriding script values

wintry quarry
#

and when and where it's appropriate to be serializing values

polar acorn
radiant frigate
languid spire
wintry quarry
ivory bobcat
wintry quarry
#

if you made your variable public or used [SerializeField] then you have serialized the variable.

mint remnant
#

I just be working in the code and go up top to see what value something is then realize later oh crap, it's not that value, I adjusted it in inspector

obsidian shoal
#

is programming 3d or 2d easer?

wintry quarry
#

the same

languid spire
obsidian shoal
#

should i continue on my 3d path or start 2d on unity

wintry quarry
#

It really doesn't matter

#

whatever type of game you want to make

polar acorn
#

2D is just 3D with a different dropdown on the camera and 2D at the end of a bunch of physics components

normal cairn
#

Hey there, im coming from unreal so not entirely used to the manual button tick calls.
But does anyone know why this is happening in my physics update? (This is the only playerArialState print in my script)

polar acorn
#

That green underline is important -- see what your compiler thinks about that

ivory bobcat
normal cairn
#

Always something simple ๐Ÿ˜‚

#

Thanks guys, was overthinking it

languid spire
#

gotta love the way it jumps out at you (pun intended)

mint lodge
#

Does hitting Play after Compiling usually take a lot of time too?

#

Because in Unreal, it was instant

half egret
#

If you enable play mode settings and keep reload domain/scene disabled

#

It'll be instant

#

And compiles only trigger on code changes

#

If you have singletons/static classes your states my not be reset as a note

#

So be mindful

polar acorn
languid spire
ionic zephyr
#

If I want my tools to have ranks (F,E,A,S+) that define their quality, should it be an Enum?

#

any Ideas?

#

suggestions are accepted

thorny basalt
#

Assuming you mean in-game tools

ionic zephyr
#

yeah, sorry

mint remnant
#

if they start to have more functionality you might decide later to go with a scriptable object and have each tool have different settings

ionic zephyr
#

and I will add an enum parameter

#

How can I distinguish the functions of my different tools that all have the SO: Tool?????

cosmic dagger
ionic zephyr
cosmic dagger
ionic zephyr
mint remnant
#

sounds like perhaps a good case for a delegate method

cosmic dagger
#

the components define its โ€” the tool's โ€” behaviour . . .

eternal needle
#

SO would be just simply to provide data to the tool. You could write functions on it but thatd be assuming theres no state associated with it

zenith cypress
# half egret

I highly recommend keeping Reload Scene enabled at least. I've hit some weird bugs with it off when some objects don't refresh (was something like some Starts didn't re-run or similar I don't fully remember atm).

eternal needle
#

To actually create a tool, you should be reading from the SO and basically abandoning it after

cosmic dagger
ionic zephyr
#

what is the architecture of that?

eternal needle
#

Not sure of what minecraft does specifically, but I would start with a tool base class which could be a component. Then on that base class you could make an OnHit or OnUse, whatever you want to name it

cosmic dagger
zenith cypress
ionic zephyr
#

but how does the game know what you are holding?

cosmic dagger
#

a simple check . . .

ionic zephyr
#

in the case of Unity

eternal needle
#

It doesnt, you make that functionality

#

There is no concept of holding

midnight meteor
#

!learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

shell herald
#

currently sturlling a bit with this. i want a 3d object to follow a spline while also following the player position. sort of like in this quick sketch. what would be a good place to start

tough phoenix
#
public void SetCoinText(float value) => m_coinText.text = $"{value}";
//
public void SetCoinText(float value) => m_coinText.text = value.ToString();

is there any difference in performance between them?

willow scroll
#

But the difference is small enough for you to ignore

tough phoenix
#

thanks ๐Ÿ™‚

willow scroll
#

Also, make sure you know TMP_Text.SetText(string) exists

tough phoenix
#

arent these the same?

willow scroll
willow scroll
tough phoenix
iron blade
#

Hello, how could I make it so when the player goes through something (a coin) it disappears (the coin in this situation)? (I'm looking to know how to do it in both 3D and 2D)

shell herald
#

a curve made of multiple points

willow scroll
#

The player is, probably, not a trigger, so OnCollisionEnter should be used

flint python
#

How do I get the same size circle as the circle collider 2D?

rich adder
#

You have scale at 20 times more

slender nymph
#

You've scaled the object rather than just changing the size of the circle collider, so you need to take the scale into account

raw token
iron blade
#

Is anything wrong with this script?

strong wren
iron blade
#

the ground has no tag

#

and the coin has the tag "Coin"

strong wren
#

Are you visibly colliding with the coin?

languid spire
#

Then your Coin collider is not setup correctly

iron blade
#

oh wait

#

It gets printed when I touch the ground because its colliding, but it didnt pass the condition

#

yet still, nothing happens when i touch the coin so it isnt detecting it

languid spire
#

screenshot coin collider

iron blade
#

okay

languid spire
#

yep, that's a trigger so you are using the wrong method

iron blade
languid spire
#

OnTriggerEnter ?

iron blade
#

hmm alright

strong wren
#

Looks like you are most likely walking right through it instead of actually colliding with it, as triggers don't collide in that sense

iron blade
#

Yup it works now, thanks

flint python
rich adder
ripe hill
#

im learning how to make 2d games but what's up with this random artifacts that im getting while playing the game in game view can anyone help me out

rich adder
ripe hill
wintry quarry
#

Google it

wintry quarry
#

unity pixel perfect

#

It's for your camera

ripe hill
#

yes on it thanks guys

stiff abyss
#

How to turn off shadow on 3d terrian

desert temple
#

Running into an odd situation. I'm trying to drag my UI Text object from my hierarchy underneath my canvas, to a public variable in my game manager, but it won't accept it. Anyone know why this is?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    //Here is where we're going to create the variables for score and lives.  Also holds references to these text objects.
    public int lives;
    public int score;
    public Text livesText;
    public Text scoreText;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

The answer is probably something simple, but I feel like I'm going crazy.

wintry quarry
#

and your actual UI element is probably a TextMeshPro UGUI

#

which you should use TMP_Text for in your code

desert temple
#

Okay, so the tutorial was lying to me because it was old.

#

So it should be what, UnityEngine.TextMeshProUGUI? And TMP_Text for the public variables?

wintry quarry
#

other than using TMPro;

halcyon dagger
#

My game runs OK in Unity but when I create a build and open it it looks like this lmao, does anyone know how to fix? Music is playing tho. Might be something in project settings?

wintry quarry
#

(make a development build)

halcyon dagger
#

should i enable something else?

wintry quarry
#

nope just that

#

then make the build and run it

#

then check the log file

halcyon dagger
#

Inside a ton of lines of dependecy loading and engine type stuff

#

No errors if running inside unity also

wintry quarry
#

You need to look at the player log as I mentioned

halcyon dagger
#

nothing seems to be wrong there

#

just showing the memory usage and class loading

wintry quarry
#

well what are you expecting your game to look like

halcyon dagger
#

It should load the start menu as it does inside Unity

wintry quarry
#

which looks like?

halcyon dagger
#

just a placeholder but yeah it should load i guess

#

๐Ÿค”

wintry quarry
#

well one of two things is happening basically:

  1. It's loading a different scene (check your build settings)
  2. You have something like an execution order issue in your code
halcyon dagger
#

Nothing wrong here

polar acorn
halcyon dagger
#

"You have something like an execution order issue in your code"

Shouldnt that pop as a big bad red error message in the console when runing the game ?

polar acorn
halcyon dagger
polar acorn
halcyon dagger
#

So, how do u debug that?

wintry quarry
#

Debug.Log

halcyon dagger
#

where

wintry quarry
#

or the debugger

#

in a development build

wintry quarry
wintry quarry
polar acorn
eternal falconBOT
#
๐Ÿ“ Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

halcyon dagger
#

The thing is that everything is working OK

halcyon dagger
wintry quarry
#

If it was working ok you wouldn't be here

halcyon dagger
#

Guess ur right

polar acorn
#

A development build is a checkbox on the build screen. Enable that, run it again, and see if you can grab the logs

halcyon dagger
wintry quarry
#

Maybe share the log with us, btw

polar acorn
#

Oh, yes. That's the ones, seems Praetor already told you about it, I just showed up

#

Yeah, post the log, using a paste side like !code suggests

eternal falconBOT
polar acorn
#

It's not actually code but it'll work anyways

halcyon dagger
polar acorn
halcyon dagger
#

alr

polar acorn
#

Hm, are you sure this is the log from the standalone build?

#

Or is the log just not actually checking if it's in-editor

halcyon dagger
#

Btw I had the same happen in an older project, but if I restarted the game it would work, it was a first time only thing

polar acorn
#

What prints the Game running inside editor line?

halcyon dagger
# polar acorn What prints the `Game running inside editor` line?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{

    void Awake()
    {
        if (!Application.isEditor && SceneManager.GetActiveScene().buildIndex != 0)
        {
            Destroy(gameObject);
        }
        else
        {
            Debug.Log("Game running inside editor");
        }
    }

}

this class

#

it shouldnt trigger until itt switches to a different scene tho

polar acorn
#

Er, wait, other way around

wintry quarry
#

honestly why such a weird singleton implementation

halcyon dagger
#

yeah but wait lemme explain that

raw token
#

I'm trying to create a super basic ray from a cinemachine-controlled camera through the center of the viewport/frustum. But using either of the implementations below, the Physics Debugger is always drawing the ray on the lower left bound of the frustum:

Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
Ray ray = Camera.main.ViewportPointToRay(Vector3.one * 0.5f);

Am I overlooking something very silly? ๐Ÿ˜ฆ

wintry quarry
#

Basically looks like your GameManager is likely to be destroying itself

wintry quarry
#

the first one certainly seems correct

polar acorn
halcyon dagger
# halcyon dagger yeah but wait lemme explain that

So I use singleton pattern to play audio, manage scenes, inputs, etc, but if im debugging a scene that aint the first menu, where the singleton is initialized, it thows a ton of errors since im trying to access methods of a null instance. so to fix that i attach a prefab of my temporary game manager to the scene, and use that script to destroy it if im not in the editor cuz its not needed.

raw token
wintry quarry
polar acorn
wintry quarry
raw token
raw token
wintry quarry
polar acorn
raw token
#

That's what I'm digging for right now ๐Ÿ˜

I was confident there were no physics queries in this scene, but maybe I've overlooked one and thought I was looking at my ray. Or this scene is haunted ๐Ÿ‘ป

elder raptor
#
private async UnlockPaths()
{
    await pathToBuilding[0].GetComponent<PathRise>().MovePlatformsUp();
    pathToBuilding[1].GetComponent<PathRise>().MovePlatformsUp();
}

How do I get this to work? I want the first function to finish running then it should start the second one. This one is not working, should I turn the MovePlatformsUp to tasks or something?

wintry quarry
#

async IEnumerator???

#

Are you writing an async function, or are you writing a coroutine? Pick one.

polar acorn
wintry quarry
#

I want the first function to finish running then it should start the second one.
This is in fact how all code in C# works by default

#

unless MovePlatformsUp is itself async

elder raptor
#

Await uses Async so Ienumerator is not needed

wintry quarry
elder raptor
#

Alright, so this is my MovePlatformsUp function

 public void MovePlatformsUp()
 {
     StartCoroutine(MovePlatformsCoroutine());
 }

 private IEnumerator MovePlatformsCoroutine()
 {
     foreach (GameObject obj in platforms)
     {
         Vector3 newPosition = obj.transform.position;
         newPosition.y -= yOffset;
         obj.transform.position = newPosition;
     }

     for (int i = 0; i < platforms.Count; i++)
     {
         GameObject obj = platforms[i];
         obj.SetActive(true);
         yield return StartCoroutine(MoveToInitialPosition(obj, initialYPositions[i]));
     }
 }

So, I have them attached to different platforms. So, what I am trying to do in the function I shared earlier is that I want to move the first platform up, and after the function (Coroutine) finishes running, I want to move the second platform up.

wintry quarry
mint lodge
#

?? suddenly red now

wintry quarry
elder raptor
#

Ahh

mint lodge
halcyon dagger
raw token
#

Alright, thanks for the sanity check Praetor & digi ๐Ÿ˜

wintry quarry
wintry quarry
#

you're missing a using directive

#

Let your IDE fix it for you with the appropriate using directive

mint lodge
#

Ohhh

polar acorn
# mint lodge

Do you have the namespace imported? Try checking the suggested fixes in your IDE

elder raptor
#

Yessir, I changed it to that lemme see if it works!

mint lodge
#

Thanks guys

wintry quarry
elder raptor
#

Yes yes, I did !

halcyon dagger
#

in a scale from 1 to 10, 1 being actually viable, and 10 being burning me like a witch,how shitty is this

using System;
using UnityEngine;

public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T _instance;

    protected virtual void Awake()
    {
        if (_instance == null)
        {
            _instance = this as T;
            DontDestroyOnLoad(gameObject);
        }
        else if (_instance != this)
        {
            Destroy(gameObject);
        }
    }
}



public class MyAudioManager : Singleton<MyAudioManager>
{
    public static MyAudioManager instance;

//so here i automarically inherit awake 
}
slender nymph
#

remove the instance variable from the derived class and just give the base class a read only property that exposes the already existing _instance variable

halcyon dagger
slender nymph
#

sure, or you can write it more simply as public static T Instance => _instance;

#

those are functionally the same though

halcyon dagger
#

alright thats bud

#

however

#

whats the rating

#

should I be publicly executed or is it an OK solution?

slender nymph
#

this is pretty much the same as any other singleton implementation

burnt vapor
#

Just the thing Boxfriend mentioned

halcyon dagger
#

So, no downsides and it aint spaguetti code?

burnt vapor
#

Considering it's exactly how a Singleton should be implemented it would be a 9

#

I would only remove the excess else and return; in the if-statement

halcyon dagger
#

A 9 like good or a 9 like this

#

๐Ÿ˜‚

burnt vapor
#

Oh, then it's a 2

#

I didn't realize 1 was positive here

halcyon dagger
#

fair enough

halcyon dagger
burnt vapor
#
    protected virtual void Awake()
    {
        if (_instance == null)
        {
            _instance = this as T;
            DontDestroyOnLoad(gameObject);
            return;
        }
        Destroy(gameObject);
    }
halcyon dagger
#

btw thanks both @slender nymph and @burnt vapor for helping โค๏ธ

burnt vapor
#

Or even better, reverse the if statement

#
    protected virtual void Awake()
    {
        if (_instance != null)
        {
           Destroy(gameObject);
           return;
        }

        _instance = this as T;
        DontDestroyOnLoad(gameObject);
    }
#

This way happy flow is at the bottom

#

Generally you expect the code to end positively at the bottom

#

And now you have a guard clause preventing it because something happened that should not happen

halcyon dagger
#

like I take a quick look at the code after a few time and I understand it faster

summer stump
#

Under "generic implementation"

burnt vapor
halcyon dagger
#

whats the difference between guard and else, wont they be executed anyways if the if block fails?

ripe shard
burnt vapor
#

Yes, it works to reduce nesting but that is not the point of it

silver lagoon
#

private bool PotionCollide()
{
return Physics2D.CircleCast(new Vector2(transform.position.x, transform.position.y), potSize, Vector2.right, enemyLayer);
}

This circle cast always returns true, even when not overlapping any other game objects. Any ideas as to why?

burnt vapor
halcyon dagger
burnt vapor
#

Yes, it would avoid the mistake of not calling the base awake by simply preventing its use entirely

ripe shard
summer stump
halcyon dagger
polar acorn
halcyon dagger
#

I kind of carried that until today

summer stump
slender nymph
halcyon dagger
summer stump
halcyon dagger
#

I meant, that depeding of that, there are cases where is better to use only 1 return per method, and others where it works the opposite way

signal mango
halcyon dagger
#

obviously everywhere the return ends the method

slender nymph
halcyon dagger
#

sorry if i didnt explain correctly

signal mango
#

I found them while looking at how Unity handles built-in messages in a disassembler

#

They're used in a few places in the C# reference sources too

halcyon dagger
north oar
#

my visual studio doesnt look like the one from a tutorial im watchin and it doesnt give a list of code when i type something in it not sure what im doin wrong ๐Ÿค”

silver lagoon
polar acorn
eternal falconBOT
silver lagoon
polar acorn
silver lagoon
#

Rigidbody, position and collider are all null for this object

polar acorn
#

So then it doesn't hit anything. Maybe your function should check if that object is null or not instead of checking if the RaycastHit2D exists?

silver lagoon
#

If it doesn't hit anything, shouldn't it return false

polar acorn
#

That was the first link I sent

silver lagoon
#

I meant that, when the call for the function was 'if (PotionCollide())', the function always returned true. Why is this?

polar acorn
#

You should be checking if the object the ray hits is null

silver lagoon
polar acorn
silver lagoon
#

So hit.collider <> null

summer stump
safe radish
#

i have a mesh for my fluid now. can anyone give me a good suggestion for how to fill in the sides?

modest sierra
#

ah yes, code "beginner"

#

Try your luck in cude advanced or code general

#

People in this channel usually are amateurs (not all but a lot) to help beginners. The more advanced people with coding are on the other chats

polar acorn
#

(yeah tbh this is a bit beyond even me at this point I do not fuck with fluid sim, even minecraft-like)

stuck palm
#

what does dirty mean?

ionic zephyr
#

does somebody know how to make a process in which you click an inventory slot and passes the object to the crafting slot and removes it TEMPORARILY from the inventory? Then, if the player doesnt want to craft anything with it, it clicks on the crafting slot and the object returns to the inventory, can somebody help me?

#

Ive tryed lots of ways but they dont convince me

rocky canyon
#

"unclean"

polar acorn
ionic zephyr
ionic zephyr
polar acorn
#

Why would a slot hold a click event

ionic zephyr
polar acorn
ionic zephyr
polar acorn
#

What's different about it?

ionic zephyr
polar acorn
#

Do you have any sort of system that can detect what object you've clicked on

polar acorn
#

figure out how to detect which slot you click on

ionic zephyr
#

the Ihandler interface

ionic zephyr
ionic zephyr
polar acorn
ionic zephyr
#

yeah

polar acorn
#

So what's different between these slots?

#

What do they do differently

copper python
ionic zephyr
polar acorn
ionic zephyr
#

and I if I use the interface then ALL of my slots would be clickable and I dont want that

polar acorn
#

So, you have a function to add an item to an inventory, and you have a function that adds an item to the crafting grid. You click on a slot in the inventory, add its item to the crafting grid. Click on a slot in the crafting grid, add it to the inventory

ionic zephyr
#

yes

ionic zephyr
ionic zephyr
copper python
#

Ah I see, I might be able to help aswell

copper python
ionic zephyr
ionic zephyr
copper python
#

ah

ionic zephyr
copper python
#

what I refer to by inventory was the intire menu which shows the slots/containers

copper python
ionic zephyr
copper python
#

fair enough

ionic zephyr
copper python
#

should the user be able to select at which slot in the crafting grid the selected item needs to be positioned?

copper python
#

That makes it simple damn

polar acorn
copper python
#

Okey, this is how I would program the inventory system:

Inventory script

  • Manages display or enable/disable of the inventory.
  • Manages on click and gets the clicked slot.
  • Manages logic of transfering items between player slots and crafting slots.

Slot script

  • Stores what kind of slot it is (player slot or crafting slot)
  • (Optionally) Stores the index or id of slot.
  • Stores item inside the slot (can be null).
copper python
#

On click you can see whether the slot is of kind player or crafting and add logic to it. For simply transfering items from one slot to the other the code would look something like this:

bool isHoldingItem = false;

Slot firtClickedSlot;

void OnInventoryClick(Slot clickedSlot) {
  if (!isHoldingItem) { // If statement for the first clicked slot.
    firstClickedSlot = clickedSlot;
    isHoldingItem = true;
  }
  else { // If statement for the second clicked slot.
    // Check if the click on the second slot is valid.
    // Optionally you could check if the clicked slot already contains an item.
    if ((firstClickedSlot.slotType == SlotType.Player 
        && clickedSlot.slotType == SlotType.Crafting)
        || (firstClickedSlot.slotType == SlotType.Crafting 
        && clickedSlot.slotType == SlotType.Player) 
    {
      TransferItemBetweenSlots(firstClickedSlot, clickedSlot)
    }
    else {
      // Invalid selection of the second slot.
    }
  }
}

void TransferItemBetweenSlots(slotFrom, slotTo) {
  slotTo.item = slotFrom.item;
  slotFrom.item = null;

  // Reset variables
  isHoldingItem = false;
  firstClickedSlot = null;
}
#

@ionic zephyr This would be simular to how I would build the inventory system. Hopefully it will help you

copper python
#

Yeah I like to get over my head alot XD

ionic zephyr
copper python
#

clickedSlot.slotType == SlotType.Crafting

ionic zephyr
copper python
ionic zephyr
copper python
#

You could ask others though

ionic zephyr
copper python
#

Btw obviously you'll have to fill in the blank gaps yourself, such as detecting when the user clicked a slot. As an example a simple button could be the way to go

#

Goodluck!

queen adder
#

I am getting NRE for this slider.value = BaseDeath.currentHealth; does this mean currentHealth is equal to 0

wintry quarry
#

slider or BaseDeath

queen adder
#

How would I get a refrence i putcs public Slider slider; and public BaseDeath BaseDeath;

wintry quarry
#

Either in the inspector

#

Or in your code

queen adder
wintry quarry
#

Yes obviously

#

You need to get the reference somehow

#

The code cannot simply guess which object you want

queen adder
#

My problem is i have no idea how do you any ways to reference an object?

queen adder
wintry quarry
#

Yes I know lots of ways

#

It really depends on the situation

queen adder
#

Will that link tell me how I should be doing it when I need a variable from another script?

wintry quarry
#

Yes

#

But "when I need a variable from another script" is ALL of the situations

#

It doesn't narrow anything down about the situation

queen adder
wintry quarry
#

Explain the situation

summer stump
wintry quarry
#

Like "this is for a health bar when a player gets hit by a bullet which is Instantiated from a prefab" or something

queen adder
#

I apologize im new i dont mean to do this

summer stump
#

In OnTrigger or OnCollision

queen adder
queen adder
#

Am i missing something? BaseDeath baseDeath = GetComponent<BaseDeath>(); slider.value = baseDeath.currentHealth;

#

I am i have an NRE im just so confused on what is missing

wintry quarry
raw token
#

An NRE occurs when you try to access a member on null. So like foobar.someMember will throw an NRE if foobar is null.

There's two member accessors in the code you've posted, so the NRE can only be a result of slider and/or baseDeath being null. With that in mind, double check where those variables are assigned values. Use Debug.Log()s to find which is null

queen adder
#

slider is getting a value in the inspector and baseDeath should have a value from the getcomponent the value should be the script baseDeath

raw token
#

Don't work off of your assumptions - test them. Usually the computer does not operate according to our assumptions, and it has a better reason for what it's doing than we have for our guesses

queen adder
polar acorn
#

The line before the NRE, log every variable that can be null

queen adder
#

I understand something is null/0 but i think im giving everything a value but obviously im not and i think the problem is in GetComponent

queen adder
#

found it baseHealthBar is Null ```{
baseHeathBar baseHeathBar = collider.GetComponent<baseHeathBar>();
if (collider.CompareTag("enemy"))
{
Debug.Log(baseHeathBar);
takeDamage(currentHealth);
baseHeathBar.setBaseHealth(currentHealth);
Debug.Log(baseHeathBar);
}

}```

#

So that means the GetComponent is not doing anything is there something wrong with the GetComponent

raw token
#

Cool cool. So the next question is "Why is GetComponent() returning null?" To answer that question, we turn to the documentation

queen adder
#

Alright ill look through the docs and ill see whats wrong

teal viper
lethal swallow
queen adder
teal viper
queen adder
#

sure one second

teal viper
queen adder
#

I originally assumed doing a check to see if the nodes are overlapping i should delete them but same result

queen adder
queen adder
#

50f

raw token
queen adder
teal viper
# queen adder 50f

That look like a lot. Considering the actual walkable area is limited, you would often get a point that is outside it, and then it gets clamped to the closest navmesh corner via sample position.

queen adder
#

Makes sense, i originally made it alot because the actual level/map is really huge

#

But i havent thought of changing it for the current scene

#

So i lower the roam radius and this happens.

queen adder
teal viper
#

You could try limiting the sampling radius to something like 0.1, so that most position outside the walkable area are ingnored. Other than that, you'll need a more sophisticated algorithm, or place the nodes manually.@queen adder

lethal swallow
queen adder
teal viper
raw token
#

(Or at least I'm assuming this is in some OnCollision method, or similar - I haven't actually seen that)

queen adder
#

Thanks a lot Raccoon you were a big help!

outer coral
#

is there some particular reason that print statements just lag the crap out of the game only in the build...

Everything runs perfect and then I add a single print statement and it lags the crap out of the game whenever its called...

only a print statement... i dont get it

slender nymph
#

have you actually profiled a build to determine that is the actual cause of performance issues?

outer coral
#

yes it is genuinely the cause

slender nymph
#

i will also point out that writing to a file can be a costly action. but i'd like to see actual data that proves that a single print statement is causing performance issues

outer coral
#

well tbf the print statement is in update but regardless

#

idk its happened in multiple spots now

slender nymph
outer coral
#

like ill print something for testing and then build without removing it and im like whys it so laggy, i remove the prints and it fixes everything

slender nymph
#

when i asked if you used the profiler i wasn't just asking if you made a guess that the print statement was the cause. i was actually asking if you had actually profiled your game to get real data instead of making assumptions

outer coral
#

okay well how can I do that

slender nymph
#

by using the profiler . . .

outer coral
#

every time I use that it just has a big block with some built in unity function 500 calls down the stack

#

thats what I get

#

i think thats what it is by the looks of it

#

same thing no print statement

sand heath
#

quantum console v-v

raw token
# outer coral

Is this the hierarchy when having a lag spike selected? Is that DirectX call taking a lot of time?

From some googlefu, it sounds like that's Unity just waiting for your computer to draw the frame, nothing to do with your code or Unity's performance. In this case it was a user's RGB lighting program which was responsible for burdening their system's resources.

steep rose
#

look at what he suggested

outer coral
#

if my rgb program is making my game lag when im printing out a float value im gonna flip

raw token
# outer coral

In that screenshot your whole player loop is only taking 7ms... It's very unlikely that the player loop is responsible for a lag spike on this frame

outer coral
#

ok hows this lol

#

everything else is at 0

#

or very low

raw token
#

Yeah, that looks like more of a problem frame

outer coral
#

i have no clue whats causing it I tried force ending most of my 3rd party application tabs including rgb programs has not helped thus far though

sand heath
#

doesnt wait for target framerate just mean its waiting for vsync?

sand heath
#

Application target framerate i believe is vsync related (if vsync is enabled it will be tied to the vsync count rather than the target fps)

outer coral
sand heath
#

yeah it seems strange to me that a debug log would be causing any noticable amount of lag unless it was concatenating a bunch of strings or doing something more expensive than just the base debug.log

#

i would only think that its not the log but whatever the log is related to

sand heath
#

that would also let you see if its actually the logs

outer coral
outer coral
sand heath
#

just disable them and see if that fixes it

#

then you can actually like be sure that its the logs

#

it might be an antimalware program or something scanning the log file

teal viper
# outer coral

This might be hardware drivven vsync. Check your GPU control panel and make sure there are no vsync related settings enabled.

#

That or you just have a gpu spike. Maybe check the GPU profiler module to see what the gpu does on that frame

gaunt cypress
#

Hey everyone. I hope you had a good week bateman_nice. Sorry for the newbie question.

What's an efficient/recommended way of creating animation transitions for lots of different animations? I have animation for walking in each direction, running in each direction, idle, jump, etc. I tried to connect them and create rules individually, but it became a mess. I heard something about Blend Trees, but I haven't had the chance to check it out.

Any ideas? Thank you so much!

thorny basalt
#

You can play animations with blender or queued

outer coral
outer coral
outer coral
outer coral
slender dock
#

can you guys spot the thing that took me over 2 hours to debug?

elder raptor
#

I am changing the mouse cursor through code using Cursor.SetCursor() and it does work, but the aspect ratio of the cursor image is wrong, it looks squashed as its Y Scale is low, how do I fix it?

marble hemlock
#

how would i go about putting a hole in a game object

#

like i have a square, and i want to completely hollow out that square so they could move through it

#

like a vent

elder raptor
crystal chasm
elder raptor
#

Unless that hole is dynamic

marble hemlock
#

oh blender how i cant escape you ๐Ÿ˜ฎโ€๐Ÿ’จ

elder raptor
#

You can do it in Unity too but it's just a bit overcomplicated xD as you should code mesh changes.

marble hemlock
#

perhaps there is only suffering

elder raptor
#

xD it's like a 10 seconds job in Blender though

marble hemlock
#

so as im waiting for blender to get up and running again

#

is probuilder not a good choice

thorny basalt
slender dock
#

feels like that semicolon after the else should come up as an error or something, but i guess there's a warning underline thingie under it

thorny basalt
slender dock
#

was a few weeks of 7 days a week, 16+ hour days, finally done'ish

slender dock
thorny basalt
slender dock
#

no error

#

guess it's valid c# :I~

#

compiler is like ... "yeah that looks good thumbs up"

marble hemlock
thorny basalt
slender dock
#

i haven't used probuilder, but watched video tutorials on it

thorny basalt
#

Well, that is why you need to learn how to debug

slender dock
#

blender works great for me, i want to try probuilder some time though, is it free?

marble hemlock
#

i dont seem to have been charged so i'll say yes

slender dock
#

neat

marble hemlock
#

i went to window -> packet manager -> all
and then just installed it

slender dock
#

i've been learning more about debugging last few weeks, but with this project if i step through code too slowly, the lobby/relay might time out

marble hemlock
#

i dont believe this is meant to be used for any final things though, but i could be wrong

#

prototyping

#

back to blender it seems

#

i forgor how to use blender its already over before it began

proud kindle
#

I converted from roblox studio to unity

#

Bec obv reasons

#

Can anyone send me a good tut vid

#

For Vr/Ar projects

marble hemlock
#

i forgot how to do basic things in blender its so over

#

YEAHHH

#

THANKS GUY

#

ONE DRIVE CEASE EXISTENCE IMMEDIATELY

vale karma
#

Hello, Im having some trouble keeping clean code. I have been doing okay with managing spegetti, there really isnt much beside this growing interact script. Can someone direct me in the right area to research? ive been looking at event systems but they are very hard to comprehend fsr

#

It all works without bugs btw, very well crafted but brittle code lol

radiant frigate
#

does someone know why this line throws me an error? spawner = gameObject.GetComponentInParent<FlyingSkullSpawnerScript>;
it says that i cant convert a group of methods into a non delegated type "flyingSkullSpawnerScript

#

or something like that, im literally translating the error since i have it in spanish

vale karma
#

is that script in the scene at runtime?

radiant frigate
#

it should be

vale karma
#

ive seen it before, its like the script doesnt have monobehavior in it or something

radiant frigate
vale karma
#

im not sure bud

raw token
radiant frigate
#

oh

vale karma
#

ahah

radiant frigate
#

indeed

#

that was it

#

lmao

vale karma
#

i remember doing that now loll

radiant frigate
#

dapper raccoon at rescate again

#

how you doing?

raw token
#

Well enough - thanks for asking :)

It's late and one of the smoke detectors in my apartment has gone rogue, but it's not long for this world, just as soon as I figure out which one it is >:)

radiant frigate
#

hope you find it soon!

#

and also that your pillow is always on the cold side

#

because you deserve it

raw token
#

hahaha, thanks!

#

May yours be as well

kind stratus
#

Hey

radiant frigate
#

hi

kind stratus
#

How are you?

#

Good at coding?

radiant frigate
#

not that much

kind stratus
#

Dm me

#

Know fnaf?

radiant frigate
#

yes i do

kind stratus
#

Dm me

radiant frigate
#

but i think its better to ask your questions here since there is a bigger base of people to help you

marble hemlock
#

CEASE EXISTENCE IMMEDIATELY

#

fucking with my file paths even though ive already deleted you
cease existence

#

i have to redownload it to fix the file paths ๐Ÿ—ฟ

eternal needle
# vale karma https://paste.ofcode.org/XgZRUuue9huVysrhHrLz9y

It looks like those 3 methods, water dirt and seed, can directly be replaced with 1 method call just using inheritance. You really shouldnt be using invoke like that. Also since those are unity objects, you shouldn't be using ? on them either.
They should either implement the same interface or be derived from the same base class.

pliant sleet
#

does someone know why I can't anchor a raw image ? like it doesn't appear anymore

#

it should have been on the transform

pallid nymph
#

seems like debug view

eager spindle
#

you're on the Debug page rather than the Inspector page

pliant sleet
#

oh my days

#

thank you

elder raptor
#

Why is only the first gameobject a bit to the left when compared to others? I am using a vertical Layout Group with the following settings.

#

It's only the DoD gameObject for some reason. No matter how I rearrange it, the DoD is stuck to the left. All of them are literal duplicates of the Name GameObject

#

Deleting it and re-making that object fixed it, but I want to know why this is happening ๐Ÿ˜” Very weird

idle ginkgo
#

when i setTrigger an anim parameter

#

sometimes it gets stuck and doesnt get untriggered?

#

why is this

slender nymph
#

have you confirmed that your ResetTrigger call is actually executing?

idle ginkgo
#

if i havent set any Reset trigger

#

it still resests ?

short hazel
idle ginkgo
#

oh ok

short hazel
#

If you do not have a transition like this, it will never reset unless you call ResetTrigger in the code

#

If you do have a transition like this, make sure it's being used. While in play mode you can select the object in the scene that has the animator, and view its state in real time

idle ginkgo
#

thanks a lot

#

fixed it

pearl temple
#

When discussing singletons in unity I see a lot of people online deriving their singleton class from monobehaviour and also attach it to some game object. Is there a reason for that?
If its just a code singleton class why not just use new instead of instantiate?

errant pilot
#

Guys do I use this type?

languid spire
languid spire
pearl temple
#

huh, isn't a singleton always a static class? There is supposed to be only one

#

oh wait, yeah I get it

#

nvm, ty

languid spire
#

no, a Singleton contains a static reference to a class instance

wintry quarry
errant pilot
languid spire
errant pilot
#

oh mb

#

i see it now

#

thank you

atomic holly
#

Hi
I want to implement differents weapons with their owns mechanical (bow, magic book can use some spells, sword, hammer...). For this, can I use some ScriptableObjects or it's not recommanded ?

willow scroll
languid spire
errant pilot
willow scroll
atomic holly
willow scroll
atomic holly
#

So don't do ScriptableObject but use a class ?

willow scroll
errant pilot
atomic holly
willow scroll
#

I would have a class Player, which has its Weapon variable

public abstract class Weapon : ScriptableObject
{
    public abstract void Attack();
}
wintry quarry
languid spire
#

you dont just have one SO you have one per weapon and use an inheritance hierarchy for the comonalities

atomic holly
willow scroll
iron blade
#

Hello! I am transitioning from an idle animation to another one using a trigger. How can I go back from the other animation to the idle one after it ends?

vague oyster
#

what doing this code?

languid spire
wintry quarry
willow scroll
vague oyster
errant pilot
atomic holly
errant pilot
#

thank you

iron blade
willow scroll
languid spire
atomic holly
languid spire
iron blade
vague oyster
#
using GooglePlayGames.BasicApi;
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GooglePlayServicesManager : MonoBehaviour
{
    public void Start()
    {
        PlayGamesPlatform.Activate();
        Social.localUser.Authenticate((bool succes) => { });
    }

   
        ```

why it don't work?
languid spire
#

wdym 'doesn't work' that code does not do anything

ivory bobcat
vague oyster
languid spire
#

That looks like a completely different API

vague oyster
vague oyster
loud mango
#
void Update()
    {
        if(movementJoystick.Direction.x > 0.001 && movementJoystick.Direction.x != 0 || movementJoystick.Direction.x < 0.001 && movementJoystick.Direction.x != 0){
            animControl.SetBool("isMoving", true);
        } else{
            animControl.SetBool("isMoving", false);
        }
    }```
wintry quarry
languid spire
atomic holly
loud mango
languid spire
slender nymph
loud mango
#

i want it so that it check if the x value is either more than zero or less than zero and then check if its not 0

#

i want it to check for !0 for the else{}

slender nymph
#

if it is more or less than 0 then you already know it isn't 0. so the check for 0 is unnecessary

loud mango
#

ooo wait

languid spire
#

yes, but you appear not to know how if statements are executed

loud mango
#

i am a big cat brain

#

so i removed the !0 part

#

and imma fix the animation cuz i just realized that it has a frame that is same as the idle animation

wintry quarry
#

You should either be checking against -.001 there or just using the absolute value

atomic holly
#

Is it normal I can create a SO with this script : ```c#
using UnityEngine;

[CreateAssetMenu(fileName = "New Weapon", menuName = "Inventory/Item/Weapon")]
public abstract class Weapon : ScriptableObject
{
public int damage;
public int reach;
public int speed;

public abstract void Attack();

}

Is it absract the problem ?
loud mango
#

i first checked if the velocity changes, if it does then the animation starts

#

but that was kinda weird

#

but imma try that again cuz now i have uniform speeds

loud mango
languid spire
shell herald
#

im mega confused. i have been debugging this script for a while now and i just dont understand what is wrong. can anyone tell me why the Debug.Log i marked in the pic is not called?

full code: https://hastebin.com/share/payiyotaru.csharp

atomic holly
steep rose
languid spire
slender nymph
steep rose
loud mango
#

oh, forgot it was there. sorry

languid spire
loud mango
hollow vortex
#

I am trying to shoot a trail from the gun point, forward to its rotation

void Shoot()
{
    if (HandHolder.childCount == 0) return;
    HandHolder.GetComponentInChildren<HandScript>().Shoot();

    Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector3 direction = (mousePosition - shootStart.position).normalized;

    RaycastHit2D hit = Physics2D.Raycast(shootStart.position, direction, weaponRange);

    GameObject trail = Instantiate(bulletTrail, shootStart.position, HandHolder.rotation);
    TrailScript tr = trail.GetComponentInChildren<TrailScript>();
    if (hit.collider != null)
    {
        tr.SetEndPos(hit.point);
    }
    else
    {
        Vector3 endPosit = shootStart.position + direction * weaponRange;
        tr.SetEndPos(endPosit);
    }
}v

its only shooting to the same point

blazing mauve
#

im making a 3d game ive coded movement and all that but idk why but my player jus walks through the walll can anyone help?

blazing mauve
shell herald
#

i think i found the issue. the methods are called with FindObjectOfType, exept interact. so when i have multiple objects with that script. in only one of them _isSpeaking is true and in all others its not.

my guess is, that if i want to call the methods on not just one object but all objects i need to use FindObjectsOfType instead but then idk how to call the method

hollow vortex
languid spire
#

and do any of them have a Rigidbody?

blazing mauve
languid spire
steep rose
hollow vortex
#

did u set any of the colliders to trigger or sum?

steep rose
#

Try what Steve and drip ward said as well

#

Good responses

hollow vortex
#

or 2d

blazing mauve
hollow vortex
steep rose
#

Are the walls triggers?

#

And floor

blazing mauve
steep rose
#

You still have the capsule collider though right?

steep rose
#

Check if it's a trigger

#

Same with the walls and floor

blazing mauve
steep rose
#

Look under the inspector and it should say "istrigger"

vague oyster
#

why vs studio print error

languid spire
blazing mauve
steep rose
blazing mauve
#

alr

steep rose
#

Colliders dont just do that unless something that shouldn't be ticked is

vague oyster
languid spire
vague oyster
steep rose
# blazing mauve

Your level doesn't have a collider on it? Also mesh colliders require a mesh field to be occupied by the mesh so it can make a collider for it

steep rose
#

I said remove it if your walls were just boxes and add box colliders instead

blazing mauve
#

and my jump script works now aswell

#

ty

short hazel
# vague oyster Cannot convert from "method group" to "System.Action<bool>".

To be accepted into the Authenticate() method, your ProcessAuthentication method must adhere to the Action<bool> delegate type, which requires:

  1. Your method must return void (that is the case right now)
  2. Your method must take a single parameter of type bool (that is NOT the case - you take in a parameter of type SignInStatus instead)
willow scroll
vague oyster
short hazel
#

That's not what I suggested you to do - you do not call the method in Start, you change its signature

#

And these docs might be for a newer version of the library

vague oyster
short hazel
#

Yes, it created the correct one for you on lines 15-18. The one on lines 20 and after is incompatible

#

On GitHub you can see files from other branches using the dropdown at the top-left, see if there's one matching your version

vague oyster
lethal bolt
#

Google didnt really know what i was asking about. How do i Check if a gameobjects Getcomponent BoxCollider is triggered?

atomic holly
#

void OnTriggerEnter(Collider collision){}

#

And if it's a collider 2D it's OnTriggerEnter2D(Collider collision){}

shell matrix
#

I can't see the default functions like start or in this case Update in unity

lethal bolt
atomic holly
#

You can't see a function in Unity

atomic holly
rich adder
shell matrix
#

visual studio does not see it as a default method

lethal bolt
rich adder
#

also 2D or 3D

atomic holly
atomic holly
atomic holly
lethal bolt
vague oyster
#

is this the correct code? it dont work

using GooglePlayGames.BasicApi;
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;



public class GooglePlayServicesManager : MonoBehaviour
{
    public void Start()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        // enables saving game progress.
        .EnableSavedGames()
        // requests the email address of the player be available.
        // Will bring up a prompt for consent.
        .RequestEmail()
        // requests a server auth code be generated so it can be passed to an
        //  associated back end server application and exchanged for an OAuth token.
        .RequestServerAuthCode(false)
        // requests an ID token be generated.  This OAuth token can be used to
        //  identify the player to other services such as Firebase.
        .RequestIdToken()
        .Build();

        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

        // authenticate user:
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => {
            // handle results
        });

        // show leaderboard UI
        Social.ShowLeaderboardUI();
    }

}
#

Why ๐Ÿ‘Ž

languid spire
#

And where did you copy/paste/generate this code from coz you damn sure did not write it

vague oyster
#

From the plugin documentation

languid spire
#

then ask the plugin writers

vague oyster
#

Ok

rich adder
vague oyster
#

Okay thank you

shell herald
#

i need a 5 second break between these two sections. how would i do that it the method is only called once?

crystal chasm
#

Split it into 2 methods, and Invoke the 2nd half

rich adder
#

make this function a coroutine

shell herald
#

that was what im looking for thx

shell herald
#

maybe im messing something up, but shouldnt the MoveAgent() be called after the duration (in this case 5 sec) is over?

half egret
#

StartCoroutine(Delay(5));

rich adder
#

You should bother reading those

shell herald
#

ah

ionic zephyr
#

how can I use AddComponent? I dont get it

half egret
#

You just do
x = this.AddComponent<TypeOfComponent>() no new is required

ionic zephyr
#

But I am not trying to add a component to the gameobject with the script

willow scroll
ionic zephyr
#

I want to create new instances of a component and adding them onto a list

summer stump
eager spindle
#

always wondered why c#, System's MathF and Unity's Mathf all don't have any checks to see if a number is between something. Would be nice if we could just min <= number <= max or Mathf.IsBetween(number, min, max)

rich adder
ionic zephyr
#

I get this error

half egret
#

It needs to be of the type GameObject, see John Smith

rich adder
#

you're trying to add a component to something that wasnt created yet..

summer stump
# ionic zephyr

Well yeah, you add components to a gameobject
And what nav said

ionic zephyr
copper python
eager spindle
summer stump
rich adder
ionic zephyr
rich adder
#

why dont you just make prefabs instead of doing this mess

ionic zephyr
#

I am creating InventorySlot class List

ionic zephyr
summer stump
eager spindle
copper python
# ionic zephyr

prob because youre using slot twice, try renaming either variable

eager spindle
#

slot doesnt exist

rich adder
eager spindle
#

you cant do anything to something that doesnt exist

ionic zephyr
eager spindle
# ionic zephyr

youll also need to show us more code than this so we can help you re-organise your syntax

eager spindle
#

make your code readable

#

dont end up like me

summer stump
#

Components exist on gameobjects

rich adder
#

components live on gameobjects

summer stump
#

You can use POCOs, but then you do not use components

rich adder
#

thats the whole point of component based system unity is based on

copper python
#

Can't you use a scriptable object for the slot?

eager spindle
#

you don't have to inherit from MonoBehaviour if you don't need it's functionality

ionic zephyr
#

okay, nevermind

#

sorry for all this mess

#

๐Ÿ™

copper python
#

We're here to help

shell herald
#

i have this river here and instead of having to place dozens of audio sources along it, i much rather would set a single audio source to the point of a spline following the river that is the closest to the player. i ve seen in the docs that there is a function called GetNearestPoint in the unity spline utilities. but it uses float3 point positions instead of worldspace vector 3s and that confuses the hell out of me.

Anyone know how to achieve this in a not overly complicated manner?

rich adder
#

float3 works fine where vector3 works

stone saddle
#

Would anyone happen to know why whenever i press play, the text on 2 random buttons is getting deleted by this script? It started happening after I implemented the destroyBallsChildren function and the (not written by me) stuff to do with instances. https://pastebin.com/VgXWusu6

arctic ibex
#

Trying to run my code. Any clue what this means? I don't really have any context cause I have not the faintest clue what could be related. Happy to provide any extra info if it's needed

tall depot
#

uhmm hello, im having a lil problem with a code .3.

rich adder
#

clear and move on basically

arctic ibex
#

oh okay, thanks.

#

Uh, I also somehow forgot o say that a button is not pressing for somereason

arctic ibex
#

like in the game

arctic ibex
rich adder
#

do you have Event System in the scene ?

arctic ibex
#

I'm pretty sure it's in the camera by default, let me check

#

yup, it's not in the camera but its there

rich adder
#

ideally should be on its own gameobject

#

ok inspect it during playmode and try clicking button see what it says in the inspector for it

arctic ibex
#

the button was working earlier

rich adder
#

you need to uncollapse the window at bottom right

arctic ibex
#

what window?

#

far out, nevermind, i figured it out

#

the button compnent isn't enabled

#

okay, code debugging time i guess, that should definitely be enabled

#

thankyou for helping

rich adder
arctic ibex
#

oh neat thanks

shell herald
#

just quick confirmation, the Items[] and the Amounts[] are always the same size, so would this cycle through them equally?

ionic zephyr
#

Hey guys, Im trying to make that whenever an update is made on the ABSTRACT inventory (player gets an object for example) this is then traduced onto the UI, however what my logic does is to get rid of what was before and start from scratch, is it okay?

rich adder
shell herald
tall depot
#

Im trying make a suikagame clone, at the moment in which 2 same tag objects collide make a new one, the problem here is that they get duplicated instead of be one, the script is assigned to each prefab (the pals)

rich adder
#

also !code

eternal falconBOT
tall depot
# rich adder what editor is this

im new in this sorry :c

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Merge : MonoBehaviour
{
    //Variables
    public Scorescript scorescript;
    public GameObject pal;
    public string tagToMerge;
    public int scoretoadd = 0;
    private bool hasMerged = false;

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (!hasMerged && collision.transform.CompareTag(tagToMerge))
        {
            hasMerged = true;

            GameObject palsContainer = GameObject.Find("PalsContainer");

            if (palsContainer != null)
            {
                GameObject newPal = Instantiate(pal, transform.position, Quaternion.identity);

                if (scorescript != null)
                {
                    scorescript.scorenumber += scoretoadd;
                    Debug.Log(scorescript.scorenumber);
                }

                newPal.transform.SetParent(palsContainer.transform);
            }

            Destroy(collision.gameObject);
            Destroy(gameObject);
        }
    }

}
polar acorn
# tall depot Im trying make a suikagame clone, at the moment in which 2 same tag objects coll...

Each instance of this object runs `OnCollisionEnter. So they each destroy each other and spawn a new one. Since it doesn't matter which one runs this code, whenever you've confirmed the two objects are the same tag to destroy and spawn a new one, compare this object's InstanceID to the other. If it's lower, return from the function early and don't do anything else. The other object will handle destroying and spawning.
https://docs.unity3d.com/ScriptReference/Object.GetInstanceID.html

tall depot
#

i dont wanna be kinky but can it be solved by dm? because im sure i will have more than this problem

polar acorn
#

no

stuck palm
#

trying to use a layermask for my own system. would comparing two layermasks return true if one had like layer1 and layer2 selected and one only had layer2 selected?

tall depot
#

hmm i have this theory: if i set the script in palscontainer and check by the instance id the same type of pals are colliding?

primal trench
#

how would i make a child in a scene into a prefab?

polar acorn
rich adder
#

also not a code question

stuck palm
slender nymph
#

did you read the section i linked to?

verbal dome
#

The answer is right there

stuck palm
#

so i might be stupid

primal trench
stuck palm
#

i want it to return true if at least one is ture

#

isnt that what OR is?

tall depot
#

honestly idk what to do :/
thats why i said to dm

polar acorn
tall depot
polar acorn
tall depot
polar acorn
#

I'm not sure what any of this has to do with the answer I gave

languid spire
#

I think he means he has no idea whatsoever what the code does or how it works

polar acorn
#

It sounds like your just describing how adding components to objects works, and I don't know what that has to do with what I said

tall depot
#

honestly yes :c
and insert triggered meme

polar acorn
#

I'm not making your game for you. You've gotten the answer. If you don't know how to implement an if statement, consider !learn or one of the tutorials linked in the pins

eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

tall depot
#

ok, im just sorry for being so dumb

languid spire
midnight meteor
#

hello , should i keep using rigidbody for player movement if i want to customize it like i want ? i'm thinking of something similar to celeste

summer stump
languid spire
#

that will depend what you want and as you dont mention that, who knows

summer stump
#

Of course all coding is customizing....
You will be forced to customize it

midnight meteor
summer stump
shell herald
#

i have an array of bools and need to use them in an if statement. is there a way to check if all bools inside an array are true?

languid spire
midnight meteor
summer stump
#

But a dynamic rigidbody will react to forces, and a kinematic one will require you to handle forces... ๐Ÿคทโ€โ™‚๏ธ

Your alternative is to use the transform (STRONGLY not recommended) or a CharacterController

shell herald
languid spire
#

the short answer is, if you want unity physics use a rigidbody

midnight meteor
summer stump
languid spire
rocky canyon
#

well do u want stuff to fall, bump, collide

#

or do u wanna fake all that stuffs

summer stump
#

Why would you think WE could know what you want....

midnight meteor
rocky canyon
#

well if u dont use real physics

summer stump
rocky canyon
#

i tend to use Kinematics Rigidbodies

#

CC is easiest up and getting going solution for beginners imo

midnight meteor
#

aight got you appreciate y'all for help

languid spire
#

but at somepoint bad design decisions WILL come back and bite you on the arse

waxen adder
#

How do you detect collisions with a player character who's using a character controller?

languid spire
#

Character Controller has it's own physics method

rocky canyon
#

a trigger collider will detect the CC but for regular Collisions u need to use the CC. method

waxen adder
#

Gotcha, thank you!

sage mirage
#

Hey, guys! Can somebody help me in making Anti-aliasing for my game?

#

I have installed URP packages and I think I am ready to make it but I am not sure how.

stuck palm
#

when building, will debug.log stuff get stripped out of the compiled code?

rocky canyon
#

i believe so..

#

dont quote me tho

#

if not i have lots of refactoring to do before building

shell herald
#

as far as im aware debug logs are also in builds unless disabled in the playersettings

halcyon dagger
#

Hey! Asked yesterday but still havent managed to solve this, does anyone know why my game build looks like this? It works fine inside Unity framework

rocky canyon
#

hes correct

#

for builds the debugs get logged in a text file in ur Build's Data Directory

stuck palm
#

oh right

#

thanks!

atomic holly
#

Hi,
I want to choose from Unity a function between a list of differents functions. Is it possible to do this with an enum ?

slate haven
#

Hey, I wanted my crosshair to follow my mouse cursor but as u can see when I start the game it just goes at the bottom of left of screen and stays there and reads minor mouse movements.

{
    [SerializeField] private RectTransform cross;
    [SerializeField] private Canvas canvas;

    void Update()
    {
        Vector2 mousePos = Mouse.current.position.ReadValue();
        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, mousePos, Camera.main, out Vector2 localPoint);
        cross.localPosition = localPoint;
    }
}```
halcyon dagger
# slate haven Hey, I wanted my crosshair to follow my mouse cursor but as u can see when I sta...

Want to make your own games in Unity? Check out our course in partnership with Unity Technologies:

https://gamedevhq.com/shop/product/2-the-ultimate-guide-to-game-development-with-unity/

Hey everyone! In todays tutorial we take a look at a 3 part series regarding creating a turret that lets you have a mouse follow, applying a cross hair, addi...

โ–ถ Play video
atomic holly